#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
struct stack *createStack(int /*<<< orphan*/);
int /*<<< orphan*/ isEmpty(struct stack *);
char pop(struct stack *);
int /*<<< orphan*/ push(struct stack *, char);
int /*<<< orphan*/ strlen(char *);
void reverse(char str[]) {
  struct stack *stack = createStack(strlen(str));
  if (!stack) {
    assert(0);
  }
  for (int i = 0; str[i]; i++) {
    push(stack, str[i]);
  }
  int i = 0;
  while (!isEmpty(stack)) {
    str[i++] = pop(stack);
  }
  str[i] = '\0';
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <createStack@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <reverse+0x32>
xor    %edi,%edi
call   1050 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11ce <reverse+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1080 <push@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <reverse+0x39>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <isEmpty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f3 <reverse+0x93>
jmp    1218 <reverse+0xb8>
mov    -0x10(%rbp),%rdi
call   1040 <pop@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d5 <reverse+0x75>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <createStack@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1183 <reverse+0x23>
xor    %edi,%edi
call   1050 <assert@plt>
mov    (%r14),%al
test   %al,%al
je     11a6 <reverse+0x46>
lea    0x1(%r14),%rbx
xchg   %ax,%ax
movsbl %al,%esi
mov    %r15,%rdi
call   1080 <push@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <reverse+0x30>
mov    %r15,%rdi
call   1070 <isEmpty@plt>
test   %eax,%eax
je     11b6 <reverse+0x56>
xor    %eax,%eax
jmp    11de <reverse+0x7e>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <pop@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1070 <isEmpty@plt>
test   %eax,%eax
je     11c0 <reverse+0x60>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stack*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = call %struct.stack* @createStack(i32 %7)
store %struct.stack* %8, %struct.stack** %3
%9 = load %struct.stack*, %struct.stack** %3
%10 = icmp ne %struct.stack* %9, null
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @assert(i32 0)
br label %13
13: ; preds = %11, %1
store i32 0, i32* %4
br label %14
14: ; preds = %29, %13
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %14
%22 = load %struct.stack*, %struct.stack** %3
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @push(%struct.stack* %22, i8 signext %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %14
32: ; preds = %14
store i32 0, i32* %5
br label %33
33: ; preds = %38, %32
%34 = load %struct.stack*, %struct.stack** %3
%35 = call i32 @isEmpty(%struct.stack* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = load %struct.stack*, %struct.stack** %3
%40 = call signext i8 @pop(%struct.stack* %39)
%41 = load i8*, i8** %2
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %33
46: ; preds = %33
%47 = load i8*, i8** %2
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
ret void
}

LLVM IR (-O2):
%struct.stack = type { i32 }
define void @reverse(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call %struct.stack* @createStack(i32 %2)
%4 = icmp eq %struct.stack* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @assert(i32 0)
br label %7
7: ; preds = %5, %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %13, %7
%11 = tail call i32 @isEmpty(%struct.stack* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %21, label %30
13: ; preds = %7, %13
%14 = phi i64 [ %17, %13 ], [ 0, %7 ]
%15 = phi i8 [ %19, %13 ], [ %8, %7 ]
%16 = tail call i32 @push(%struct.stack* %3, i8 signext %15)
%17 = add nuw i64 %14, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %10, label %13
21: ; preds = %10, %21
%22 = phi i64 [ %24, %21 ], [ 0, %10 ]
%23 = tail call signext i8 @pop(%struct.stack* %3)
%24 = add nuw i64 %22, 1
%25 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 %23, i8* %25
%26 = tail call i32 @isEmpty(%struct.stack* %3)
%27 = icmp eq i32 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %21
%29 = and i64 %24, 4294967295
br label %30
30: ; preds = %28, %10
%31 = phi i64 [ 0, %10 ], [ %29, %28 ]
%32 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 0, i8* %32
ret void
}