#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*/ Reversify(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ scanf(char *, char *);
void main() {
  char *input = (char *)malloc(sizeof(char) * 31);
  char *temp = input;
  char ch;
  int i = 31 - 1;
  printf("\nEnter string to be reversed, max len 30.\n:> ");
  while (scanf("%c", &ch) && ch != '\n' && i-- >= 0) {
    *input++ = ch;
  }
  *input = '\0';
  input = temp;
  Reversify(input);
  printf("\nI am done!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1f,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1e,-0x18(%rbp)
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11b9 <main+0x79>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     11b9 <main+0x79>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
setge  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11c9 <main+0x89>
jmp    11e2 <main+0xa2>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1171 <main+0x31>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <Reversify@plt>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x1f,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1070 <scanf@plt>
mov    %r12,%rdx
test   %rax,%rax
je     11df <main+0x8f>
mov    0x7(%rsp),%al
mov    %r12,%rdx
cmp    $0xa,%al
je     11df <main+0x8f>
xor    %ebx,%ebx
lea    0xe90(%rip),%r14
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,(%r12,%rbx,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
je     11d9 <main+0x89>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
je     11d9 <main+0x89>
cmp    $0x1e,%ebx
mov    %rcx,%rbx
jne    11b0 <main+0x60>
mov    %r12,%rdx
add    %rcx,%rdx
movb   $0x0,(%rdx)
mov    %r12,%rdi
call   1060 <Reversify@plt>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [46 x i8] c"\0AEnter string to be reversed, max len 30.\0A:> \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [13 x i8] c"\0AI am done!\0A\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = call i64 @malloc(i32 31)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %1
%7 = load i8*, i8** %1
store i8* %7, i8** %2
store i32 30, i32* %4
%8 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %22, %0
%10 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = icmp sge i32 %17, 0
br label %20
20: ; preds = %16, %12, %9
%21 = phi i1 [ false, %12 ], [ false, %9 ], [ %19, %16 ]
br i1 %21, label %22, label %26
22: ; preds = %20
%23 = load i8, i8* %3
%24 = load i8*, i8** %1
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %1
store i8 %23, i8* %24
br label %9
26: ; preds = %20
%27 = load i8*, i8** %1
store i8 0, i8* %27
%28 = load i8*, i8** %2
store i8* %28, i8** %1
%29 = load i8*, i8** %1
%30 = call i32 @Reversify(i8* %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"\0AEnter string to be reversed, max len 30.\0A:> \00"
@.str.1 = [3 x i8] c"%c\00"
@str = [12 x i8] c"\0AI am done!\00"
define void @main() {
%1 = alloca i8
%2 = tail call i64 @malloc(i32 31)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%6 = icmp ne i64 %5, 0
%7 = load i8, i8* %1
%8 = icmp ne i8 %7, 10
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %23
10: ; preds = %0, %10
%11 = phi i8 [ %18, %10 ], [ %7, %0 ]
%12 = phi i32 [ %14, %10 ], [ 30, %0 ]
%13 = phi i8* [ %15, %10 ], [ %3, %0 ]
%14 = add nsw i32 %12, -1
%15 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %11, i8* %13
%16 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = icmp ne i64 %16, 0
%18 = load i8, i8* %1
%19 = icmp ne i8 %18, 10
%20 = select i1 %17, i1 %19, i1 false
%21 = icmp ne i32 %12, 0
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %10, label %23
23: ; preds = %10, %0
%24 = phi i8* [ %3, %0 ], [ %15, %10 ]
store i8 0, i8* %24
%25 = call i32 @Reversify(i8* %3)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret void
}