#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 main(void) {
  int sentence[100], i = 0;
  printf("enter a message:\n");
  char ch = getchar();
  while (ch != '\n') {
    sentence[i++] = ch;
    ch = getchar();
  }
  for (int j = (i - 1); j >= 0; j--) {
    printf("%c", sentence[j]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1a4(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1a5(%rbp)
movsbl -0x1a5(%rbp),%eax
cmp    $0xa,%eax
je     119a <main+0x7a>
movsbl -0x1a5(%rbp),%ecx
mov    -0x1a4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1a4(%rbp)
cltq
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1a5(%rbp)
jmp    1157 <main+0x37>
mov    -0x1a4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
cmpl   $0x0,-0x1ac(%rbp)
jl     11e6 <main+0xc6>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1ac(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11a9 <main+0x89>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x190,%rsp
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1195 <main+0x65>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1160 <main+0x30>
test   %ebx,%ebx
jle    1195 <main+0x65>
mov    %ebx,%ebx
add    $0x1,%rbx
nop
lea    -0x2(%rbx),%eax
mov    (%rsp,%rax,4),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1180 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"enter a message:\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %4
br label %8
8: ; preds = %12, %0
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %17
store i32 %14, i32* %18
%19 = call signext i8 (...) @getchar()
store i8 %19, i8* %4
br label %8
20: ; preds = %8
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %32, %20
%24 = load i32, i32* %5
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
br label %23
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [17 x i8] c"enter a message:\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
br i1 %5, label %19, label %11
6: ; preds = %11
%7 = trunc i64 %15 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = and i64 %15, 4294967295
br label %21
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 0, %0 ]
%13 = phi i8 [ %17, %11 ], [ %4, %0 ]
%14 = sext i8 %13 to i32
%15 = add nuw i64 %12, 1
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
store i32 %14, i32* %16
%17 = tail call signext i8 (...) @getchar()
%18 = icmp eq i8 %17, 10
br i1 %18, label %6, label %11
19: ; preds = %21, %0, %6
%20 = tail call i32 @putchar(i32 10)
ret i32 0
21: ; preds = %9, %21
%22 = phi i64 [ %10, %9 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 @putchar(i32 %26)
%28 = icmp ugt i64 %22, 1
br i1 %28, label %21, label %19
}