#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();
char *malloc(int);
int /*<<< orphan*/ printStr(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ reverse(char *);
int main(void) {
  char *str, c, *start;
  str = malloc(100 * sizeof(char));
  start = str;
  int i = 0;
  while ((i < 100 - 1) && (c = getchar()) != '\n') {
    *str++ = c;
    i++;
  }
  *str = '\0';
  printf("The original string is: ");
  printStr(start);
  printf("reversing...\n");
  reverse(start);
  printf("The reversed string is: ");
  printStr(start);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x63,-0x24(%rbp)
mov    %al,-0x25(%rbp)
jge    11a1 <main+0x51>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b1 <main+0x61>
jmp    11d3 <main+0x83>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <main+0x2c>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <printStr@plt>
lea    0xe23(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <reverse@plt>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <printStr@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     1198 <main+0x38>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x63,%ebx
jne    1180 <main+0x20>
mov    %r14,%rax
add    %rbx,%rax
movb   $0x0,(%rax)
lea    0xe58(%rip),%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <printStr@plt>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <reverse@plt>
lea    0xe49(%rip),%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <printStr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"The original string is: \00"
@.str.2 = [25 x i8] c"The reversed string is: \00"
@str = [13 x i8] c"reversing...\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
br label %2
2: ; preds = %0, %7
%3 = phi i32 [ 0, %0 ], [ %9, %7 ]
%4 = phi i8* [ %1, %0 ], [ %8, %7 ]
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 10
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %5, i8* %4
%9 = add nuw nsw i32 %3, 1
%10 = icmp eq i32 %9, 99
br i1 %10, label %11, label %2
11: ; preds = %7, %2
%12 = phi i8* [ %8, %7 ], [ %4, %2 ]
store i8 0, i8* %12
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @printStr(i8* %1)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @reverse(i8* %1)
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @printStr(i8* %1)
ret i32 0
}