#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char);
void str_rev(int n, char a[100]) {
  if (n == 2)
    printf("%c", a[0]);
  else {
    printf("%c", a[n - 2]);
    str_rev(n - 1, a);
  }
}


x86 assembly (clang, -O0):
<str_rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    1151 <str_rev+0x31>
mov    -0x10(%rbp),%rax
lea    0xebc(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
jmp    117d <str_rev+0x5d>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
lea    0xe9b(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1030 <str_rev@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_rev>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
je     1156 <str_rev+0x46>
movslq %edi,%rax
lea    (%rax,%r14,1),%r12
add    $0xfffffffffffffffe,%r12
mov    $0x2,%r13d
sub    %edi,%r13d
xor    %ebx,%ebx
lea    0xec2(%rip),%r15
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r13d
jne    1140 <str_rev+0x30>
movsbl (%r14),%esi
lea    0xe9f(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @str_rev(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %10)
br label %23
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = load i8*, i8** %4
br label %23
23: ; preds = %12, %7
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @str_rev(i32 %0, i8* nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = sext i32 %0 to i64
br label %9
6: ; preds = %9, %2
%7 = load i8, i8* %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %7)
ret void
9: ; preds = %4, %9
%10 = phi i64 [ %5, %4 ], [ %15, %9 ]
%11 = add nsw i64 %10, -2
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = add nsw i64 %10, -1
%16 = trunc i64 %15 to i32
%17 = icmp eq i32 %16, 2
br i1 %17, label %6, label %9
}