#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 */
size_t strlen(char *);
int /*<<< orphan*/ swap(char *, char *);
void reverse(char *string) {
  size_t length = strlen(string);
  if (length == 0) {
    return;
  }
  size_t low = 0;
  size_t high = length - 1;
  while (low < high) {
    swap(string + low, string + high);
    ++low;
    --high;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <reverse+0x29>
jmp    119d <reverse+0x7d>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    119d <reverse+0x7d>
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x20(%rbp),%rsi
call   1040 <swap@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <reverse+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%rax
jb     1161 <reverse+0x41>
mov    %rax,%rbx
add    $0xffffffffffffffff,%rbx
mov    $0x1,%r15d
lea    (%r14,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    (%r14,%rbx,1),%rsi
call   1040 <swap@plt>
add    $0xffffffffffffffff,%rbx
lea    0x1(%r15),%rax
cmp    %rbx,%r15
mov    %rax,%r15
jb     1140 <reverse+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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