#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 /*<<< orphan*/ printf(char *);
void reverse(char *str) {
  if (str) {
    char *end, tmp, *ancor;
    ancor = end = str;
    while (*(++end) != '\0')
      ;
    end--;
    while (str < end) {
      tmp = *end;
      *end = *str;
      *str = tmp;
      str++;
      end--;
    }
  } else
    printf("The string is NULL!");
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ae <reverse+0x9e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1154 <reverse+0x44>
jmp    1133 <reverse+0x23>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a9 <reverse+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1160 <reverse+0x50>
jmp    11ba <reverse+0xaa>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
test   %rdi,%rdi
je     115d <reverse+0x4d>
lea    -0x2(%rdi),%rax
nopl   0x0(%rax)
cmpb   $0x0,0x3(%rax)
lea    0x1(%rax),%rax
jne    1120 <reverse+0x10>
lea    0x1(%rax),%rcx
cmp    %rdi,%rcx
jbe    115c <reverse+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%rax),%ecx
movzbl (%rdi),%edx
mov    %dl,0x1(%rax)
mov    %cl,(%rdi)
add    $0x1,%rdi
lea    -0x1(%rax),%rcx
cmp    %rax,%rdi
mov    %rcx,%rax
jb     1140 <reverse+0x30>
ret
lea    0xe9c(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"The string is NULL!\00"
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %37
8: ; preds = %1
%9 = load i8*, i8** %2
store i8* %9, i8** %3
store i8* %9, i8** %5
br label %10
10: ; preds = %16, %8
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
br label %10
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 -1
store i8* %19, i8** %3
br label %20
20: ; preds = %24, %17
%21 = load i8*, i8** %2
%22 = load i8*, i8** %3
%23 = icmp ult i8* %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
store i8 %26, i8* %4
%27 = load i8*, i8** %2
%28 = load i8, i8* %27
%29 = load i8*, i8** %3
store i8 %28, i8* %29
%30 = load i8, i8* %4
%31 = load i8*, i8** %2
store i8 %30, i8* %31
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %3
br label %20
36: ; preds = %20
br label %39
37: ; preds = %1
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %37, %36
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"The string is NULL!\00"
define void @reverse(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %5, %3 ], [ %0, %1 ]
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = icmp ugt i8* %4, %0
br i1 %9, label %10, label %20
10: ; preds = %8, %10
%11 = phi i8* [ %15, %10 ], [ %0, %8 ]
%12 = phi i8* [ %16, %10 ], [ %4, %8 ]
%13 = load i8, i8* %12
%14 = load i8, i8* %11
store i8 %14, i8* %12
store i8 %13, i8* %11
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = getelementptr inbounds i8, i8* %12, i64 -1
%17 = icmp ult i8* %15, %16
br i1 %17, label %10, label %20
18: ; preds = %1
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %10, %8, %18
ret void
}