#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*/ init();
char pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(char);
int /*<<< orphan*/ reverse(char *);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char str[1000];
  int i;
  void *t;
  char tmp;
  init();
  printf("Enter string:");
  scanf("%s", str);
  printf("You Entered string: %s", str);
  reverse(str);
  printf("reverse %s\n", str);
  for (i = 0; i < strlen(str); i++) {
    push(str[i]);
  }
  for (i = 0; i < strlen(str); i++) {
    str[i] = pop();
  }
  printf("reverse(using char stack)  %s\n", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <init@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x400(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
mov    %eax,-0x418(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x418(%rbp),%eax
cmp    %ecx,%eax
jge    1241 <main+0xd1>
movslq -0x404(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%edi
ff
call   1090 <push@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    11f1 <main+0x81>
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x41c(%rbp),%eax
cmp    %ecx,%eax
jge    129e <main+0x12e>
mov    $0x0,%al
call   1060 <pop@plt>
mov    %al,%cl
movslq -0x404(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    124b <main+0xdb>
lea    -0x400(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
xor    %eax,%eax
call   1070 <init@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <reverse@plt>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11fc <main+0x8c>
xor    %ebx,%ebx
mov    %rsp,%r14
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%edi
call   1090 <push@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11e0 <main+0x70>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    122d <main+0xbd>
mov    %rsp,%r14
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1060 <pop@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1210 <main+0xa0>
lea    0xdfd(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Enter string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [23 x i8] c"You Entered string: %s\00"
@.str.3 = [12 x i8] c"reverse %s\0A\00"
@.str.4 = [31 x i8] c"reverse(using char stack) %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @init()
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%17 = call i32 @reverse(i8* %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %18)
store i32 0, i32* %7
br label %20
20: ; preds = %31, %2
%21 = load i32, i32* %7
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @push(i8 signext %29)
br label %31
31: ; preds = %25
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %20
34: ; preds = %20
store i32 0, i32* %7
br label %35
35: ; preds = %45, %34
%36 = load i32, i32* %7
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %48
40: ; preds = %35
%41 = call signext i8 (...) @pop()
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %43
store i8 %41, i8* %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %35
48: ; preds = %35
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [14 x i8] c"Enter string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [23 x i8] c"You Entered string: %s\00"
@.str.3 = [12 x i8] c"reverse %s\0A\00"
@.str.4 = [31 x i8] c"reverse(using char stack) %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @init()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%9 = call i32 @reverse(i8* %4)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%11 = call i32 @strlen(i8* %4)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %16, %2
%14 = call i32 @strlen(i8* %4)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %25, label %33
16: ; preds = %2, %16
%17 = phi i64 [ %21, %16 ], [ 0, %2 ]
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @push(i8 signext %19)
%21 = add nuw nsw i64 %17, 1
%22 = call i32 @strlen(i8* %4)
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %16, label %13
25: ; preds = %13, %25
%26 = phi i64 [ %29, %25 ], [ 0, %13 ]
%27 = call signext i8 (...) @pop()
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %26
store i8 %27, i8* %28
%29 = add nuw nsw i64 %26, 1
%30 = call i32 @strlen(i8* %4)
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %25, label %33
33: ; preds = %25, %13
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret i32 0
}