#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*/ putchar(char);
int main(void) {
  char msg[100], *p;
  printf("Enter a message: ");
  for (p = msg; p < &msg[100]; p++) {
    *p = getchar();
    if (*p == '\n')
      break;
  }
  printf("Reversal is: ");
  for (p--; p >= msg; p--)
    putchar(*p);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
lea    -0x70(%rbp),%rcx
add    $0x64,%rcx
cmp    %rcx,%rax
jae    11a5 <main+0x75>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,%cl
mov    -0x78(%rbp),%rax
mov    %cl,(%rax)
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    118f <main+0x5f>
jmp    11a5 <main+0x75>
jmp    1194 <main+0x64>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    1156 <main+0x26>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    -0x78(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
jb     11eb <main+0xbb>
mov    -0x78(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x78(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x78(%rbp)
jmp    11bd <main+0x8d>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsp,%rbx
lea    0xebf(%rip),%rdi
call   1040 <printf@plt>
lea    0x64(%rsp),%r14
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,(%rbx)
cmp    $0xa,%al
je     1166 <main+0x36>
add    $0x1,%rbx
cmp    %r14,%rbx
jb     1150 <main+0x20>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
mov    %rsp,%r14
cmp    %r14,%rbx
jb     1191 <main+0x61>
xchg   %ax,%ax
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1180 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@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"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %5, i8** %3
br label %6
6: ; preds = %19, %0
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 100
%9 = icmp ult i8* %7, %8
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = call signext i8 (...) @getchar()
%12 = load i8*, i8** %3
store i8 %11, i8* %12
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %10
br label %22
18: ; preds = %10
br label %19
19: ; preds = %18
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %6
22: ; preds = %17, %6
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
br label %26
26: ; preds = %34, %22
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%29 = icmp uge i8* %27, %28
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = call i32 @putchar(i8 signext %32)
br label %34
34: ; preds = %30
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %3
br label %26
37: ; preds = %26
%38 = call i32 @putchar(i8 signext 10)
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 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 100
br label %5
5: ; preds = %0, %9
%6 = phi i8* [ %2, %0 ], [ %10, %9 ]
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %6
%8 = icmp eq i8 %7, 10
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = icmp ult i8* %10, %4
br i1 %11, label %5, label %12
12: ; preds = %5, %9
%13 = phi i8* [ %6, %5 ], [ %10, %9 ]
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i8, i8* %13, i64 -1
%16 = icmp ult i8* %15, %2
br i1 %16, label %23, label %17
17: ; preds = %12, %17
%18 = phi i8* [ %21, %17 ], [ %15, %12 ]
%19 = load i8, i8* %18
%20 = call i32 @putchar(i8 signext %19)
%21 = getelementptr inbounds i8, i8* %18, i64 -1
%22 = icmp ult i8* %21, %2
br i1 %22, label %23, label %17
23: ; preds = %17, %12
%24 = call i32 @putchar(i8 signext 10)
ret i32 0
}