#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 strlen(char *);
int /*<<< orphan*/ swap(char *, char *);
void reverse(char *str) {
  if (str == NULL) {
    return;
  }
  int i;
  int j;
  for (i = 0, j = strlen(str) - 1; i < j; i++, j--) {
    swap(str + i, str + j);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <reverse+0x1c>
jmp    1190 <reverse+0x70>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1190 <reverse+0x70>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <reverse+0x32>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1173 <reverse+0x53>
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1173 <reverse+0x53>
mov    %eax,%r15d
lea    (%r15,%r14,1),%r12
add    $0xffffffffffffffff,%r12
add    $0xfffffffffffffffe,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <swap@plt>
add    $0x1,%rbx
add    $0x1,%r14
add    $0xffffffffffffffff,%r12
lea    -0x1(%r15),%rax
cmp    %r15,%rbx
mov    %rax,%r15
jl     1150 <reverse+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
br label %31
8: ; preds = %1
store i32 0, i32* %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %4
br label %12
12: ; preds = %26, %8
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @swap(i8* %20, i8* %24)
br label %26
26: ; preds = %16
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
br label %12
31: ; preds = %7, %12
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
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = zext i32 %4 to i64
%8 = add nsw i64 %7, -1
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %15, %9 ]
%11 = phi i64 [ %8, %6 ], [ %16, %9 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = tail call i32 @swap(i8* %12, i8* %13)
%15 = add nuw nsw i64 %10, 1
%16 = add nsw i64 %11, -1
%17 = icmp slt i64 %15, %16
br i1 %17, label %9, label %18
18: ; preds = %9, %3, %1
ret void
}