#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 length(char *);
void reverse(char str[]) {
  int start = 0;
  int end = length(str) - 1;
  char holder;
  while (end > start) {
    holder = str[end];
    str[end] = str[start];
    str[start] = holder;
    end--;
    start++;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <length@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1187 <reverse+0x77>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <reverse+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
mov    %rdi,%rbx
call   1030 <length@plt>
cmp    $0x2,%eax
jl     1151 <reverse+0x41>
mov    %eax,%eax
add    $0xfffffffffffffffe,%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rbx,%rax,1),%esi
movzbl (%rbx,%rcx,1),%edx
mov    %dl,0x1(%rbx,%rax,1)
mov    %sil,(%rbx,%rcx,1)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rcx,%rax
mov    %rdx,%rax
jg     1130 <reverse+0x20>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @reverse(i8* %0) {
%2 = tail call i32 @length(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = zext i32 %2 to i64
%6 = add nsw i64 %5, -1
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ 0, %4 ], [ %14, %7 ]
%9 = phi i64 [ %6, %4 ], [ %15, %7 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 %8
%13 = load i8, i8* %12
store i8 %13, i8* %10
store i8 %11, i8* %12
%14 = add nuw nsw i64 %8, 1
%15 = add nsw i64 %9, -1
%16 = icmp sgt i64 %15, %14
br i1 %16, label %7, label %17
17: ; preds = %7, %1
ret void
}