#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 *);
int strlen(char *);
int reverseString(char *string) {
  char temp;
  int length = strlen(string);
  int beg = 0, end = length - 1;
  if (length <= 0) {
    printf("\nERROR : wrong input\n");
    return 1;
  }
  while (beg < end) {
    temp = string[end];
    string[end] = string[beg];
    string[beg] = temp;
    beg++;
    end--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<reverseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     116a <reverseString+0x4a>
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cb <reverseString+0xab>
jmp    116f <reverseString+0x4f>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c4 <reverseString+0xa4>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    116f <reverseString+0x4f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    1176 <reverseString+0x56>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
je     1187 <reverseString+0x67>
mov    %ecx,%ecx
add    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%r14,%rcx,1),%esi
movzbl (%r14,%rdx,1),%ebx
mov    %bl,0x1(%r14,%rcx,1)
mov    %sil,(%r14,%rdx,1)
add    $0x1,%rdx
lea    -0x1(%rcx),%rsi
cmp    %rcx,%rdx
mov    %rsi,%rcx
jl     1150 <reverseString+0x30>
jmp    1187 <reverseString+0x67>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0AERROR : wrong input\0A\00"
define i32 @reverseString(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %5
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %7
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %46
16: ; preds = %1
br label %17
17: ; preds = %21, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %45
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
store i8 %26, i8* %4
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = load i8, i8* %4
%37 = load i8*, i8** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
%43 = load i32, i32* %7
%44 = add nsw i32 %43, -1
store i32 %44, i32* %7
br label %17
45: ; preds = %17
store i32 0, i32* %2
br label %46
46: ; preds = %45, %14
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@str = [21 x i8] c"\0AERROR : wrong input\00"
define i32 @reverseString(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = icmp eq i32 %2, 1
br i1 %5, label %21, label %6
6: ; preds = %4
%7 = zext i32 %2 to i64
%8 = add nsw i64 %7, -1
br label %11
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %21
11: ; preds = %6, %11
%12 = phi i64 [ 0, %6 ], [ %18, %11 ]
%13 = phi i64 [ %8, %6 ], [ %19, %11 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %0, i64 %12
%17 = load i8, i8* %16
store i8 %17, i8* %14
store i8 %15, i8* %16
%18 = add nuw nsw i64 %12, 1
%19 = add nsw i64 %13, -1
%20 = icmp slt i64 %18, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %4, %9
%22 = phi i32 [ 1, %9 ], [ 0, %4 ], [ 0, %11 ]
ret i32 %22
}