#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 *);
void reverse_char_array(char *str) {
  if (str == NULL)
    return;
  if (*str == '\0')
    return;
  char *start = str;
  char *end = start + strlen(str) - 1;
  char temp;
  while (end > start) {
    temp = *start;
    *start = *end;
    *end = temp;
    ++start;
    --end;
  }
}


x86 assembly (clang, -O0):
<reverse_char_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <reverse_char_array+0x1c>
jmp    11b7 <reverse_char_array+0xa7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1141 <reverse_char_array+0x31>
jmp    11b7 <reverse_char_array+0xa7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11b7 <reverse_char_array+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <reverse_char_array+0x5e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_char_array>:
push   %rbx
test   %rdi,%rdi
je     115c <reverse_char_array+0x4c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     115c <reverse_char_array+0x4c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    115c <reverse_char_array+0x4c>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%ecx
movzbl (%rax),%edx
mov    %dl,-0x1(%rbx)
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rbx),%rcx
cmp    %rbx,%rax
mov    %rcx,%rbx
ja     1140 <reverse_char_array+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @reverse_char_array(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 eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
br label %39
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %39
15: ; preds = %9
%16 = load i8*, i8** %2
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -1
store i8* %22, i8** %4
br label %23
23: ; preds = %27, %15
%24 = load i8*, i8** %4
%25 = load i8*, i8** %3
%26 = icmp ugt i8* %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
store i8 %29, i8* %5
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
store i8 %31, i8* %32
%33 = load i8, i8* %5
%34 = load i8*, i8** %4
store i8 %33, i8* %34
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %4
br label %23
39: ; preds = %8, %14, %23
ret void
}

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