#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverseIt(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char *stringBuffer;
  if (argc != 2) {
    fprintf(stderr, "Usage: This program reverses one string passed as\n"
                    "an arguement from the command line.\n");
    exit(-1);
  }
  stringBuffer = malloc(strlen(argv[1]));
  strcpy(stringBuffer, argv[1]);
  reverseIt(stringBuffer);
  printf("The reversed string is '%s'\n", stringBuffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1090 <reverseIt@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11bc <main+0x4c>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1090 <reverseIt@plt>
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [87 x i8] c"Usage: This program reverses one string passed as\0Aan arguement from the command line.\0A\00"
@.str.1 = [29 x i8] c"The reversed string is '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcpy(i8* %19, i8* %22)
%24 = load i8*, i8** %6
%25 = call i32 @reverseIt(i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %26)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [87 x i8] c"Usage: This program reverses one string passed as\0Aan arguement from the command line.\0A\00"
@.str.1 = [29 x i8] c"The reversed string is '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = tail call i8* @malloc(i32 %11)
%13 = load i8*, i8** %9
%14 = tail call i32 @strcpy(i8* %12, i8* %13)
%15 = tail call i32 @reverseIt(i8* %12)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12)
ret i32 0
}