#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 atoi(char *);
int get_line(char *, int);
int getop(char *);
int /*<<< orphan*/ itoa(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse(char *);
int strindex(char *, char *);
int main() {
  char foo[20] = "foobar";
  char bar[50];
  int baz;
  reverse(foo);
  printf("Let's test reverse(\"foobar\"): %s\n", foo);
  printf("Enter some text to test get_line(): ");
  if ((baz = get_line(bar, 50)) > 0) {
    printf("get_line() returns %d and updates to: %s", baz, bar);
  }
  printf("atoi(): %d\n", atoi("7529"));
  itoa(-4321, bar);
  printf("itoa(): %s\n", bar);
  printf("strindex(\"foobarness\", \"bar\"): %d\n",
         strindex("foobarness", "bar"));
  printf("Enter a RPN equation to test getop(): ");
  printf("getop(): %d, %s\n", getop(bar), bar);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe75(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x20(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x32,%esi
call   1040 <get_line@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jle    11f6 <main+0x86>
mov    -0x64(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rsi
mov    $0xffffef1f,%edi
call   1090 <itoa@plt>
lea    -0x60(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <strindex@plt>
mov    %eax,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <getop@plt>
mov    %eax,%esi
lea    -0x60(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movaps 0xe94(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <reverse@plt>
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rdi
mov    $0x32,%esi
call   1040 <get_line@plt>
test   %eax,%eax
jle    11ca <main+0x6a>
lea    0xe9f(%rip),%rdi
lea    0x20(%rsp),%rdx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x1d69,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rbx
mov    $0xffffef1f,%edi
mov    %rbx,%rsi
call   1080 <itoa@plt>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1070 <strindex@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <getop@plt>
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.foo = [20 x i8] c"foobar\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [34 x i8] c"Let's test reverse(\22foobar\22): %s\0A\00"
@.str.1 = [37 x i8] c"Enter some text to test get_line(): \00"
@.str.2 = [41 x i8] c"get_line() returns %d and updates to: %s\00"
@.str.3 = [12 x i8] c"atoi(): %d\0A\00"
@.str.4 = [5 x i8] c"7529\00"
@.str.5 = [12 x i8] c"itoa(): %s\0A\00"
@.str.6 = [35 x i8] c"strindex(\22foobarness\22, \22bar\22): %d\0A\00"
@.str.7 = [11 x i8] c"foobarness\00"
@.str.8 = [4 x i8] c"bar\00"
@.str.9 = [39 x i8] c"Enter a RPN equation to test getop(): \00"
@.str.10 = [17 x i8] c"getop(): %d, %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [50 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [20 x i8]* %2 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = call i32 @reverse(i8* %6)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%12 = call i32 @get_line(i8* %11, i32 50)
store i32 %12, i32* %4
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* %4
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %16)
br label %18
18: ; preds = %14, %0
%19 = call i32 @atoi(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%22 = call i32 @itoa(i32 -4321, i8* %21)
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%25 = call i32 @strindex(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%29 = call i32 @getop(i8* %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %29, i8* %30)
ret i32 0
}

LLVM IR (-O2):
@__const.main.foo = [20 x i8] c"foobar\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [34 x i8] c"Let's test reverse(\22foobar\22): %s\0A\00"
@.str.1 = [37 x i8] c"Enter some text to test get_line(): \00"
@.str.2 = [41 x i8] c"get_line() returns %d and updates to: %s\00"
@.str.3 = [12 x i8] c"atoi(): %d\0A\00"
@.str.5 = [12 x i8] c"itoa(): %s\0A\00"
@.str.6 = [35 x i8] c"strindex(\22foobarness\22, \22bar\22): %d\0A\00"
@.str.7 = [11 x i8] c"foobarness\00"
@.str.8 = [4 x i8] c"bar\00"
@.str.9 = [39 x i8] c"Enter a RPN equation to test getop(): \00"
@.str.10 = [17 x i8] c"getop(): %d, %s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = call i32 @reverse(i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @get_line(i8* %4, i32 50)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %8, i8* %4)
br label %12
12: ; preds = %10, %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 7529)
%14 = call i32 @itoa(i32 -4321, i8* %4)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%16 = call i32 @strindex(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
%19 = call i32 @getop(i8* %4)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %19, i8* %4)
ret i32 0
}