#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 reverse(char *str, char *end) {
  char temp;
  printf("In %s \n", str);
  while (str && end && str < end) {
    temp = *end;
    *end = *str;
    *str = temp;
    str++;
    end--;
  }
  printf("out %s \n", str);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x12(%rbp)
je     115e <reverse+0x4e>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x12(%rbp)
je     115e <reverse+0x4e>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    116e <reverse+0x5e>
jmp    11a9 <reverse+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <reverse+0x20>
mov    -0x8(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
test   %rbx,%rbx
je     115e <reverse+0x4e>
cmp    %r14,%rbx
jae    115e <reverse+0x4e>
add    $0xffffffffffffffff,%r14
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%r14),%eax
movzbl (%rbx),%ecx
mov    %cl,0x1(%r14)
mov    %al,(%rbx)
add    $0x1,%rbx
lea    -0x1(%r14),%rax
cmp    %r14,%rbx
mov    %rax,%r14
jb     1140 <reverse+0x30>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"In %s \0A\00"
@.str.1 = [9 x i8] c"out %s \0A\00"
define void @reverse(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %8
8: ; preds = %20, %2
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = icmp ult i8* %15, %16
br label %18
18: ; preds = %14, %11, %8
%19 = phi i1 [ false, %11 ], [ false, %8 ], [ %17, %14 ]
br i1 %19, label %20, label %32
20: ; preds = %18
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
store i8 %22, i8* %5
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
store i8 %24, i8* %25
%26 = load i8, i8* %5
%27 = load i8*, i8** %3
store i8 %26, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %4
br label %8
32: ; preds = %18
%33 = load i8*, i8** %3
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"In %s \0A\00"
@.str.1 = [9 x i8] c"out %s \0A\00"
define void @reverse(i8* %0, i8* %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp ne i8* %0, null
%5 = icmp ult i8* %0, %1
%6 = and i1 %4, %5
br i1 %6, label %7, label %15
7: ; preds = %2, %7
%8 = phi i8* [ %12, %7 ], [ %0, %2 ]
%9 = phi i8* [ %13, %7 ], [ %1, %2 ]
%10 = load i8, i8* %9
%11 = load i8, i8* %8
store i8 %11, i8* %9
store i8 %10, i8* %8
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = icmp ult i8* %12, %13
br i1 %14, label %7, label %15
15: ; preds = %7, %2
%16 = phi i8* [ %0, %2 ], [ %12, %7 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret void
}