#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*/ xor_swap(char *, char *);
void reverse_string(char *str) {
  if (str) {
    char *start = str;
    char *end = start + strlen(str) - 1;
    while (start < end) {
      xor_swap(start, end);
      start++;
      end--;
    }
  }
}


x86 assembly (clang, -O0):
<reverse_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a1 <reverse_string+0x81>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119c <reverse_string+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <xor_swap@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1164 <reverse_string+0x44>
jmp    11a1 <reverse_string+0x81>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_string>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1158 <reverse_string+0x38>
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jbe    1158 <reverse_string+0x38>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <xor_swap@plt>
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
cmp    %rbx,%r14
jb     1140 <reverse_string+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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