#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 getaline(char *, int);
int /*<<< orphan*/ printdiv(char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse(char *);
int main() {
  int len;
  int max;
  char line[1000];
  printdiv('=', 70);
  printf("Using pointers instead of arrays for reverse line from chapter 1\n");
  printdiv('-', 70);
  max = 0;
  while ((len = getaline(line, 1000)) > 0) {
    if (len > max)
      max = len;
    reverse(line);
    printf("%s", line);
  }
  if (max > 1000)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3d,%edi
mov    $0x46,%esi
call   1060 <printdiv@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2d,%edi
mov    $0x46,%esi
call   1060 <printdiv@plt>
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <getaline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11da <main+0x9a>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11b4 <main+0x74>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x400(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1185 <main+0x45>
cmpl   $0x3e8,-0xc(%rbp)
jle    11f3 <main+0xb3>
movl   $0x1,-0x4(%rbp)
jmp    11fa <main+0xba>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    $0x3d,%edi
mov    $0x46,%esi
call   1070 <printdiv@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2d,%edi
mov    $0x46,%esi
call   1070 <printdiv@plt>
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1050 <getaline@plt>
test   %eax,%eax
jle    11e8 <main+0x98>
mov    %rsp,%rbx
lea    0xe60(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1050 <getaline@plt>
test   %eax,%eax
jg     11b0 <main+0x60>
xor    %eax,%eax
cmp    $0x3e9,%ebp
setae  %al
jmp    11ea <main+0x9a>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"Using pointers instead of arrays for reverse line from chapter 1\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
store i32 0, i32* %1
%5 = call i32 @printdiv(i8 signext 61, i32 70)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printdiv(i8 signext 45, i32 70)
store i32 0, i32* %3
br label %8
8: ; preds = %18, %0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%10 = call i32 @getaline(i8* %9, i32 1000)
store i32 %10, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* %2
store i32 %17, i32* %3
br label %18
18: ; preds = %16, %12
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%20 = call i32 @reverse(i8* %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %8
23: ; preds = %8
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 1000
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 1, i32* %1
br label %28
27: ; preds = %23
store i32 0, i32* %1
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@str = [65 x i8] c"Using pointers instead of arrays for reverse line from chapter 1\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printdiv(i8 signext 61, i32 70)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @printdiv(i8 signext 45, i32 70)
%6 = call i32 @getaline(i8* %2, i32 1000)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %0, %8
%9 = phi i32 [ %15, %8 ], [ %6, %0 ]
%10 = phi i32 [ %12, %8 ], [ 0, %0 ]
%11 = icmp sgt i32 %9, %10
%12 = select i1 %11, i32 %9, i32 %10
%13 = call i32 @reverse(i8* %2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = call i32 @getaline(i8* %2, i32 1000)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %8, label %17
17: ; preds = %8
%18 = icmp ugt i32 %12, 1000
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %17, %0
%21 = phi i32 [ 0, %0 ], [ %19, %17 ]
ret i32 %21
}