#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, int /*<<< orphan*/);
void reverse(char *originalString) {
  if (originalString != NULL) {
    int length = strlen(originalString);
    int backIdx = length - 1;
    int numLoops = length / 2;
    for (int frontIdx = 0; frontIdx < numLoops; frontIdx++) {
      swap(originalString, frontIdx, backIdx--);
    }
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1197 <reverse+0x77>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1192 <reverse+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    %edx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
call   1040 <swap@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1161 <reverse+0x41>
jmp    1197 <reverse+0x77>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1167 <reverse+0x47>
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1167 <reverse+0x47>
mov    %eax,%ebp
mov    %eax,%r15d
shr    $0x1f,%r15d
add    %eax,%r15d
sar    %r15d
add    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <swap@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    %ebx,%r15d
jne    1150 <reverse+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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