#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int main() {
  char s[101];
  int i;
  fputs("Please write a string: ", stdout);
  fgets(s, 101, stdin);
  puts("Your sentence in reverse: ");
  for (i = strlen(s) - 1; i >= 0; i--) {
    if (s[i] == '\n') {
      continue;
    } else {
      putchar(s[i]);
    }
  }
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <fputs@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    $0x65,%esi
call   1070 <fgets@plt>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jl     11eb <main+0x9b>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11ca <main+0x7a>
jmp    11dd <main+0x8d>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
jmp    11dd <main+0x8d>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
jmp    11a9 <main+0x59>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x65,%esi
call   1070 <fgets@plt>
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11cf <main+0x7f>
mov    %eax,%ebx
add    $0x1,%rbx
jmp    11ba <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11cf <main+0x7f>
lea    -0x2(%rbx),%eax
movzbl (%rsp,%rax,1),%eax
cmp    $0xa,%al
je     11b0 <main+0x60>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11b0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Please write a string: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [27 x i8] c"Your sentence in reverse: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stdout
%5 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 101, i32 %7)
%9 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %3
br label %13
13: ; preds = %31, %0
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %16
br label %31
24: ; preds = %16
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @putchar(i8 signext %28)
br label %30
30: ; preds = %24
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %3
%33 = add nsw i32 %32, -1
store i32 %33, i32* %3
br label %13
34: ; preds = %13
%35 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Please write a string: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [27 x i8] c"Your sentence in reverse: \00"
define i32 @main() {
%1 = alloca [101 x i8]
%2 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdout
%4 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 101, i32 %5)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @strlen(i8* %2)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %0
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %21
%13 = phi i64 [ %11, %10 ], [ %14, %21 ]
%14 = add nsw i64 %13, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 @putchar(i8 signext %17)
br label %21
21: ; preds = %12, %19
%22 = icmp ugt i64 %13, 1
br i1 %22, label %12, label %23
23: ; preds = %21, %0
%24 = call i32 @putchar(i8 signext 10)
ret i32 0
}