#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 */
struct stack {
  int dummy;
};

/* Variables and functions */
struct stack *createstack(int);
char pop(struct stack *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ push(struct stack *, char);
int strlen(char *);
void reversestr(char str[]) {
  int n = strlen(str);
  int i;
  struct stack *stack = createstack(n);
  for (i = 0; i <= n; i++)
    push(stack, str[i]);
  for (i = 0; i <= n; i++)
    str[i] = pop(stack);
  printf("\nThe reverse is %s", str);
  return;
}


x86 assembly (clang, -O0):
<reversestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <createstack@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11aa <reversestr+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1060 <push@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117b <reversestr+0x2b>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11e1 <reversestr+0x91>
mov    -0x18(%rbp),%rdi
call   1050 <pop@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b1 <reversestr+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reversestr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1070 <createstack@plt>
test   %r15d,%r15d
js     11b5 <reversestr+0x65>
mov    %rax,%r12
lea    0x1(%r15),%r13d
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1060 <push@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <reversestr+0x30>
test   %r15d,%r15d
js     11b5 <reversestr+0x65>
xor    %ebx,%ebx
nopl   (%rax)
mov    %r12,%rdi
call   1050 <pop@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <reversestr+0x50>
lea    0xe44(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.stack = type { i32 }
@.str = [19 x i8] c"\0AThe reverse is %s\00"
define void @reversestr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stack*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call %struct.stack* @createstack(i32 %8)
store %struct.stack* %9, %struct.stack** %5
store i32 0, i32* %4
br label %10
10: ; preds = %22, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load %struct.stack*, %struct.stack** %5
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @push(%struct.stack* %15, i8 signext %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %10
store i32 0, i32* %4
br label %26
26: ; preds = %37, %25
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load %struct.stack*, %struct.stack** %5
%32 = call signext i8 @pop(%struct.stack* %31)
%33 = load i8*, i8** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %30
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %26
40: ; preds = %26
%41 = load i8*, i8** %2
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %41)
ret void
}

LLVM IR (-O2):
%struct.stack = type { i32 }
@.str = [19 x i8] c"\0AThe reverse is %s\00"
define void @reversestr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call %struct.stack* @createstack(i32 %2)
%4 = icmp slt i32 %2, 0
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = add nuw i32 %2, 1
%7 = zext i32 %6 to i64
br label %12
8: ; preds = %12
br i1 %4, label %25, label %9
9: ; preds = %8
%10 = add nuw i32 %2, 1
%11 = zext i32 %10 to i64
br label %19
12: ; preds = %5, %12
%13 = phi i64 [ 0, %5 ], [ %17, %12 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i32 @push(%struct.stack* %3, i8 signext %15)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %8, label %12
19: ; preds = %9, %19
%20 = phi i64 [ 0, %9 ], [ %23, %19 ]
%21 = tail call signext i8 @pop(%struct.stack* %3)
%22 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 %21, i8* %22
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %25, label %19
25: ; preds = %19, %1, %8
%26 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
ret void
}