#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ reverse(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Missing input files.\n");
    return 1;
  }
  char a[1000];
  int lim = 1000;
  FILE *in;
  if ((in = fopen(argv[1], "r")) == NULL) {
    perror(argv[1]);
    return 1;
  }
  int len;
  lim = 1000;
  while ((len = getline(in, a, lim)) >= 0) {
    if (len == 0) {
      continue;
    }
    if (reverse(a) != 0) {
      printf("Error occured\n");
      continue;
    } else {
      printf("%s\n", a);
    }
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119d <main+0x3d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127f <main+0x11f>
movl   $0x3e8,-0x404(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x410(%rbp)
cmp    $0x0,%rax
jne    11e5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    127f <main+0x11f>
movl   $0x3e8,-0x404(%rbp)
mov    -0x410(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    -0x404(%rbp),%edx
call   1080 <getline@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jl     126c <main+0x10c>
cmpl   $0x0,-0x414(%rbp)
jne    1229 <main+0xc9>
jmp    11ef <main+0x8f>
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
cmp    $0x0,%rax
je     1252 <main+0xf2>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ef <main+0x8f>
lea    -0x400(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ef <main+0x8f>
mov    -0x410(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
cmp    $0x2,%edi
jne    11e2 <main+0x82>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120c <main+0xac>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x3e8,%edx
call   1080 <getline@plt>
test   %eax,%eax
js     11f5 <main+0x95>
mov    %rsp,%rbx
lea    0xe54(%rip),%r15
jmp    11cc <main+0x6c>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1080 <getline@plt>
test   %eax,%eax
js     11f5 <main+0x95>
test   %eax,%eax
je     11b8 <main+0x58>
mov    %rbx,%rdi
call   1030 <reverse@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %rbx,%rdi
jmp    11b3 <main+0x53>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    11ff <main+0x9f>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rbx),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11ff <main+0x9f>

LLVM IR (-O0):
@.str = [22 x i8] c"Missing input files.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Error occured\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %49
14: ; preds = %2
store i32 1000, i32* %7
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @perror(i8* %23)
store i32 1, i32* %3
br label %49
25: ; preds = %14
store i32 1000, i32* %7
br label %26
26: ; preds = %45, %40, %35, %25
%27 = load i32*, i32** %8
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %7
%30 = call i32 @getline(i32* %27, i8* %28, i32 %29)
store i32 %30, i32* %9
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %26
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
br label %26
36: ; preds = %32
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%38 = call i64 @reverse(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %26
42: ; preds = %36
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42
br label %26
46: ; preds = %26
%47 = load i32*, i32** %8
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %46, %20, %12
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@str = [14 x i8] c"Error occured\00"
@str.4 = [21 x i8] c"Missing input files.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0))
br label %36
7: ; preds = %2
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = call i32 @getline(i32* %11, i8* %8, i32 1000)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %19, label %32
16: ; preds = %7
%17 = load i8*, i8** %9
%18 = tail call i32 @perror(i8* %17)
br label %34
19: ; preds = %13, %27
%20 = phi i32 [ %28, %27 ], [ %14, %13 ]
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i64 @reverse(i8* %8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %30, %19
%28 = call i32 @getline(i32* %11, i8* %8, i32 1000)
%29 = icmp sgt i32 %28, -1
br i1 %29, label %19, label %32
30: ; preds = %22
%31 = call i32 @puts(i8* %8)
br label %27
32: ; preds = %27, %13
%33 = call i32 @fclose(i32* %11)
br label %34
34: ; preds = %32, %16
%35 = phi i32 [ 1, %16 ], [ 0, %32 ]
br label %36
36: ; preds = %34, %5
%37 = phi i32 [ 1, %5 ], [ %35, %34 ]
ret i32 %37
}