#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 *, int);
void reverse(char s[]) {
  static int length, j;
  static int prestine = 1;
  if (prestine) {
    int i;
    for (i = 0; s[i] != '\0'; i++)
      ;
    printf("%d\n", i);
    length = i - 1;
    prestine = 0;
    j = 0;
    printf("is prestine: %d\n", prestine);
  }
  if (j <= (length / 2)) {
    int t;
    t = s[j];
    s[j] = s[length];
    s[length] = t;
    length--;
    j++;
    reverse(s);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpl   $0x0,0x2efd(%rip)
je     11a9 <reverse+0x89>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1168 <reverse+0x48>
jmp    115a <reverse+0x3a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1140 <reverse+0x20>
mov    -0xc(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,0x2eb5(%rip)
movl   $0x0,0x2ea3(%rip)
movl   $0x0,0x2ea5(%rip)
mov    0x2e93(%rip),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e8d(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e80(%rip),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1235 <reverse+0x115>
mov    -0x8(%rbp),%rax
movslq 0x2e64(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq 0x2e4e(%rip),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq 0x2e44(%rip),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq 0x2e2d(%rip),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2e24(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e1b(%rip)
mov    0x2e19(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e10(%rip)
mov    -0x8(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2f12(%rip),%dil
lea    0xee4(%rip),%r14
lea    0xed0(%rip),%r15
test   $0x1,%dil
mov    $0x1,%dil
jne    118f <reverse+0x7f>
mov    $0xfffffffe,%ebx
mov    %r12,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1150 <reverse+0x40>
lea    0x1(%rbx),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebx,0x2ebf(%rip)
movb   $0x1,0x2ec0(%rip)
movl   $0x0,0x2eb2(%rip)
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x2ea5(%rip),%dil
movslq 0x2e9a(%rip),%rcx
movslq 0x2e8f(%rip),%rdx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
cmp    %esi,%ecx
jg     11d1 <reverse+0xc1>
mov    (%r12,%rcx,1),%bl
mov    (%r12,%rdx,1),%al
mov    %al,(%r12,%rcx,1)
mov    %bl,(%r12,%rdx,1)
lea    -0x1(%rdx),%eax
mov    %eax,0x2e69(%rip)
lea    0x1(%rcx),%eax
mov    %eax,0x2e64(%rip)
jmp    1130 <reverse+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@reverse.length = internal global i32 0
@reverse.j = internal global i32 0
@reverse.prestine = internal global i32 1
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [17 x i8] c"is prestine: %d\0A\00"
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @reverse.prestine
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %27
7: ; preds = %1
store i32 0, i32* %3
br label %8
8: ; preds = %17, %7
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %8
20: ; preds = %8
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
store i32 %24, i32* @reverse.length
store i32 0, i32* @reverse.prestine
store i32 0, i32* @reverse.j
%25 = load i32, i32* @reverse.prestine
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20, %1
%28 = load i32, i32* @reverse.j
%29 = load i32, i32* @reverse.length
%30 = sdiv i32 %29, 2
%31 = icmp sle i32 %28, %30
br i1 %31, label %32, label %59
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = load i32, i32* @reverse.j
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
store i32 %38, i32* %4
%39 = load i8*, i8** %2
%40 = load i32, i32* @reverse.length
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = load i8*, i8** %2
%45 = load i32, i32* @reverse.j
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
%48 = load i32, i32* %4
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %2
%51 = load i32, i32* @reverse.length
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 %49, i8* %53
%54 = load i32, i32* @reverse.length
%55 = add nsw i32 %54, -1
store i32 %55, i32* @reverse.length
%56 = load i32, i32* @reverse.j
%57 = add nsw i32 %56, 1
store i32 %57, i32* @reverse.j
%58 = load i8*, i8** %2
br label %59
59: ; preds = %32, %27
ret void
}

LLVM IR (-O2):
@reverse.length = internal unnamed_addr global i32 0
@reverse.j = internal unnamed_addr global i32 0
@reverse.prestine = internal unnamed_addr global i1 false
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [17 x i8] c"is prestine: %d\0A\00"
define void @reverse(i8* nocapture %0) {
%2 = load i1, i1* @reverse.prestine
br label %3
3: ; preds = %23, %1
%4 = phi i1 [ %18, %23 ], [ %2, %1 ]
br i1 %4, label %17, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %10, %5 ], [ 0, %3 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = add nuw i64 %6, 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = trunc i64 %6 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = add nsw i32 %12, -1
store i32 %14, i32* @reverse.length
store i1 true, i1* @reverse.prestine
store i32 0, i32* @reverse.j
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0)
%16 = load i1, i1* @reverse.prestine
br label %17
17: ; preds = %11, %3
%18 = phi i1 [ %16, %11 ], [ true, %3 ]
%19 = load i32, i32* @reverse.j
%20 = load i32, i32* @reverse.length
%21 = sdiv i32 %20, 2
%22 = icmp sgt i32 %19, %21
br i1 %22, label %32, label %23
23: ; preds = %17
%24 = sext i32 %19 to i64
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = sext i32 %20 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
store i8 %29, i8* %25
store i8 %26, i8* %28
%30 = add nsw i32 %20, -1
store i32 %30, i32* @reverse.length
%31 = add nsw i32 %19, 1
store i32 %31, i32* @reverse.j
br label %3
32: ; preds = %17
ret void
}