#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 mygetline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse_string(char *);
int main() {
  int len, i;
  char line[1000];
  len = 0;
  for (i = 0; i < 1000; i++)
    line[i] = '\0';
  printf("\nType in some lines, I will reverse the order. Enter a '$' "
         "character to end.\n\n");
  while ((len = mygetline(line, 1000)) > 0) {
    if (len >= 1000 - 1)
      printf("\nThe line is too long! Max length is %d characters.\n", 1000);
    reverse_string(line);
    printf("%s\n", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1177 <main+0x47>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1150 <main+0x20>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <mygetline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11e8 <main+0xb8>
cmpl   $0x3e7,-0x8(%rbp)
jl     11c2 <main+0x92>
lea    0xe99(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
call   1030 <reverse_string@plt>
lea    -0x400(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1185 <main+0x55>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1070 <mygetline@plt>
test   %eax,%eax
jle    11d9 <main+0x89>
lea    0xe70(%rip),%r14
mov    %rsp,%rbx
jmp    11c1 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <reverse_string@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1070 <mygetline@plt>
test   %eax,%eax
jle    11d9 <main+0x89>
cmp    $0x3e7,%eax
jb     11a0 <main+0x50>
mov    %r14,%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <main+0x50>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [79 x i8] c"\0AType in some lines, I will reverse the order. Enter a '$' character to end.\0A\0A\00"
@.str.1 = [53 x i8] c"\0AThe line is too long! Max length is %d characters.\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %5
15: ; preds = %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %26, %15
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%19 = call i32 @mygetline(i8* %18, i32 1000)
store i32 %19, i32* %2
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %2
%23 = icmp sge i32 %22, 999
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 1000)
br label %26
26: ; preds = %24, %21
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%28 = call i32 @reverse_string(i8* %27)
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %17
31: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [53 x i8] c"\0AThe line is too long! Max length is %d characters.\0A\00"
@str = [78 x i8] c"\0AType in some lines, I will reverse the order. Enter a '$' character to end.\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
%5 = call i32 @mygetline(i8* %3, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %0, %12
%8 = phi i32 [ %15, %12 ], [ %5, %0 ]
%9 = icmp ugt i32 %8, 998
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 1000)
br label %12
12: ; preds = %10, %7
%13 = call i32 @reverse_string(i8* %3)
%14 = call i32 @puts(i8* %3)
%15 = call i32 @mygetline(i8* %3, i32 1000)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %7, label %17
17: ; preds = %12, %0
ret i32 0
}