#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[]) {
  static int start;
  int end;
  int tmp;
  end = strlen(s) - start - 1;
  if (start >= end) {
    start = 0;
    return;
  }
  tmp = s[start];
  s[start++] = s[end];
  s[end--] = tmp;
  reverse(s);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    0x2ef9(%rip),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    0x2eed(%rip),%eax
cmp    -0xc(%rbp),%eax
jl     115f <reverse+0x3f>
movl   $0x0,0x2eda(%rip)
jmp    11ba <reverse+0x9a>
mov    -0x8(%rbp),%rax
movslq 0x2eca(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    0x2eae(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2ea3(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,-0xc(%rbp)
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
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <strlen@plt>
mov    0x2f01(%rip),%edx
mov    %edx,%ecx
not    %ecx
add    %eax,%ecx
cmp    %ecx,%edx
jge    1158 <reverse+0x48>
movslq %edx,%rax
movzbl (%rbx,%rax,1),%esi
movslq %ecx,%rcx
movzbl (%rbx,%rcx,1),%edx
lea    0x1(%rax),%edi
mov    %edi,0x2ee0(%rip)
mov    %dl,(%rbx,%rax,1)
mov    %sil,(%rbx,%rcx,1)
mov    %rbx,%rdi
jmp    1120 <reverse+0x10>
movl   $0x0,0x2eca(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@reverse.start = internal global i32 0
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = load i32, i32* @reverse.start
%8 = sub nsw i32 %6, %7
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %3
%10 = load i32, i32* @reverse.start
%11 = load i32, i32* %3
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* @reverse.start
br label %39
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = load i32, i32* @reverse.start
%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* %4
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%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.start
%28 = add nsw i32 %27, 1
store i32 %28, i32* @reverse.start
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
%31 = load i32, i32* %4
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = add nsw i32 %34, -1
store i32 %35, i32* %3
%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, %13
ret void
}

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