#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*/ swap(char *, char *);
void reverse(char *str) {
  char *end = str;
  if (str) {
    while (*end)
      end++;
    end--;
    while (str < end) {
      swap(str, end);
      str++;
      end--;
    }
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119b <reverse+0x8b>
jmp    1134 <reverse+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1152 <reverse+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <reverse+0x24>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1196 <reverse+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    115e <reverse+0x4e>
jmp    119b <reverse+0x8b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1148 <reverse+0x38>
mov    %rdi,%r14
lea    -0x2(%rdi),%rbx
cmpb   $0x0,0x2(%rbx)
lea    0x1(%rbx),%rbx
jne    1120 <reverse+0x10>
cmp    %r14,%rbx
jbe    1148 <reverse+0x38>
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
cmp    %rbx,%r14
jb     1130 <reverse+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %31
7: ; preds = %1
br label %8
8: ; preds = %12, %7
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %8
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %3
br label %18
18: ; preds = %22, %15
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = icmp ult i8* %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = load i8*, i8** %3
%25 = call i32 @swap(i8* %23, i8* %24)
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %3
br label %18
30: ; preds = %18
br label %31
31: ; preds = %30, %1
ret void
}

LLVM IR (-O2):
define void @reverse(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %7, %3 ], [ %0, %1 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 -1
%10 = icmp ugt i8* %9, %0
br i1 %10, label %11, label %18
11: ; preds = %8, %11
%12 = phi i8* [ %16, %11 ], [ %9, %8 ]
%13 = phi i8* [ %15, %11 ], [ %0, %8 ]
%14 = tail call i32 @swap(i8* %13, i8* %12)
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = getelementptr inbounds i8, i8* %12, i64 -1
%17 = icmp ult i8* %15, %16
br i1 %17, label %11, label %18
18: ; preds = %11, %8, %1
ret void
}