#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse(char *);
int main(void) {
  char message[100];
  char c, *p = message;
  printf("Enter a message: ");
  while ((c = getchar()) != '\n' && p < message + 100)
    *p++ = c;
  *p = '\0';
  reverse(message);
  printf("Reversal is: ");
  printf("%s\n", message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x81(%rbp)
je     118e <main+0x5e>
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
add    $0x64,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11a1 <main+0x71>
jmp    11ba <main+0x8a>
mov    -0x71(%rbp),%cl
mov    -0x80(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x80(%rbp)
mov    %cl,(%rax)
jmp    1158 <main+0x28>
mov    -0x80(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x70(%rbp),%rdi
call   1030 <reverse@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    1165 <main+0x25>
mov    %rsp,%rbx
jmp    1186 <main+0x46>
lea    0x64(%rsp),%r14
mov    %rsp,%rbx
nopl   (%rax)
mov    %al,(%rbx)
add    $0x1,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     1186 <main+0x46>
cmp    %r14,%rbx
jb     1170 <main+0x30>
movb   $0x0,(%rbx)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <reverse@plt>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter a message: \00"
@.str.1 = [14 x i8] c"Reversal is: \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i8*
store i32 0, i32* %1
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %5, i8** %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %18, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 100
%15 = icmp ult i8* %12, %14
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ false, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = load i8, i8* %3
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 %19, i8* %20
br label %7
22: ; preds = %16
%23 = load i8*, i8** %4
store i8 0, i8* %23
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%25 = call i32 @reverse(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter a message: \00"
@.str.1 = [14 x i8] c"Reversal is: \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 100
br i1 %5, label %15, label %7
7: ; preds = %0, %7
%8 = phi i8 [ %11, %7 ], [ %4, %0 ]
%9 = phi i8* [ %10, %7 ], [ %2, %0 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %8, i8* %9
%11 = call signext i8 (...) @getchar()
%12 = icmp ne i8 %11, 10
%13 = icmp ult i8* %10, %6
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %7, label %15
15: ; preds = %7, %0
%16 = phi i8* [ %2, %0 ], [ %10, %7 ]
store i8 0, i8* %16
%17 = call i32 @reverse(i8* %2)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @puts(i8* %2)
ret i32 0
}