#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 loadCharacter(int *, int);
int /*<<< orphan*/ storeCharacter(int *, int, int);
int stringLength(int *);
void stringReverse(int *s) {
  int i;
  int j;
  int tmp;
  i = 0;
  j = stringLength(s) - 1;
  while (i < j) {
    tmp = loadCharacter(s, i);
    storeCharacter(s, i, loadCharacter(s, j));
    storeCharacter(s, j, tmp);
    i = i + 1;
    j = j - 1;
  }
}


x86 assembly (clang, -O0):
<stringReverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stringLength@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11bb <stringReverse+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <loadCharacter@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <loadCharacter@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    %eax,%edx
call   1030 <storeCharacter@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <storeCharacter@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <stringReverse+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringReverse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1050 <stringLength@plt>
cmp    $0x2,%eax
jl     1192 <stringReverse+0x62>
mov    %eax,%ebp
add    $0xffffffff,%ebp
mov    $0x1,%ebx
nop
lea    -0x1(%rbx),%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <loadCharacter@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <loadCharacter@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1030 <storeCharacter@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <storeCharacter@plt>
add    $0xffffffff,%ebp
lea    0x1(%rbx),%eax
cmp    %ebp,%ebx
mov    %eax,%ebx
jl     1150 <stringReverse+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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