#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 strlen(char *);
void reverse(char s[]) {
  int c;
  static int j, i;
  if (j == 0)
    j = strlen(s) - 1;
  if (i < j) {
    c = s[i];
    s[i++] = s[j];
    s[j--] = c;
    reverse(s);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2f01(%rip)
jne    114b <reverse+0x2b>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,0x2ee9(%rip)
mov    0x2ee7(%rip),%eax
cmp    0x2edd(%rip),%eax
jge    11c1 <reverse+0xa1>
mov    -0x8(%rbp),%rax
movslq 0x2ed0(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq 0x2eba(%rip),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    0x2eb1(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2ea6(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    0x2e8d(%rip),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,0x2e82(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
mov    %rdi,%rbx
mov    0x2f12(%rip),%eax
test   %eax,%eax
jne    1131 <reverse+0x21>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
mov    %eax,0x2efb(%rip)
movslq 0x2ef8(%rip),%rcx
cmp    %eax,%ecx
jge    1167 <reverse+0x57>
movzbl (%rbx,%rcx,1),%r8d
movslq %eax,%rsi
movzbl (%rbx,%rsi,1),%edx
lea    0x1(%rcx),%edi
mov    %edi,0x2edf(%rip)
mov    %dl,(%rbx,%rcx,1)
add    $0xffffffff,%eax
mov    %eax,0x2ecf(%rip)
mov    %r8b,(%rbx,%rsi,1)
test   %eax,%eax
jne    1131 <reverse+0x21>
jmp    1120 <reverse+0x10>
pop    %rbx
ret

LLVM IR (-O0):
@reverse.j = internal global i32 0
@reverse.i = internal global i32 0
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i32, i32* @reverse.j
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
store i32 %9, i32* @reverse.j
br label %10
10: ; preds = %6, %1
%11 = load i32, i32* @reverse.i
%12 = load i32, i32* @reverse.j
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* @reverse.i
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
store i32 %20, i32* %3
%21 = load i8*, i8** %2
%22 = load i32, i32* @reverse.j
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %2
%27 = load i32, i32* @reverse.i
%28 = add nsw i32 %27, 1
store i32 %28, i32* @reverse.i
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
%31 = load i32, i32* %3
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %2
%34 = load i32, i32* @reverse.j
%35 = add nsw i32 %34, -1
store i32 %35, i32* @reverse.j
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 %32, i8* %37
%38 = load i8*, i8** %2
br label %39
39: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@reverse.j = internal unnamed_addr global i32 0
@reverse.i = internal unnamed_addr global i32 0
define void @reverse(i8* %0) {
%2 = load i32, i32* @reverse.j
br label %3
3: ; preds = %13, %1
%4 = phi i32 [ %21, %13 ], [ %2, %1 ]
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
store i32 %8, i32* @reverse.j
br label %9
9: ; preds = %6, %3
%10 = phi i32 [ %8, %6 ], [ %4, %3 ]
%11 = load i32, i32* @reverse.i
%12 = icmp slt i32 %11, %10
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = sext i32 %10 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = add nsw i32 %11, 1
store i32 %20, i32* @reverse.i
store i8 %19, i8* %15
%21 = add nsw i32 %10, -1
store i32 %21, i32* @reverse.j
store i8 %16, i8* %18
br label %3
22: ; preds = %9
ret void
}