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


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <reverse+0x1c>
jmp    118b <reverse+0x6b>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118b <reverse+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edx
mov    %edx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
call   1040 <swap@plt>
jmp    115b <reverse+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1156 <reverse+0x36>
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1156 <reverse+0x36>
mov    %eax,%ebp
add    $0xffffffff,%ebp
xor    %esi,%esi
nopl   (%rax)
lea    0x1(%rsi),%ebx
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <swap@plt>
add    $0xffffffff,%ebp
mov    %ebx,%esi
cmp    %ebp,%ebx
jl     1140 <reverse+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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