#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 /*<<< orphan*/ perror(char *);
int rev(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  FILE *file = NULL;
  if (argc < 2)
    file = stdin;
  int i, ret = 0;
  for (i = 1; i < argc || file; i++, file = NULL) {
    if (!file) {
      if (!strcmp(argv[i], "-"))
        file = stdin;
      else
        file = fopen(argv[i], "r");
    }
    if (!file) {
      perror("rev");
      ret = 1;
      continue;
    }
    int err = rev(file);
    if (file != stdin)
      fclose(file);
    if (err < 0) {
      perror("rev");
      ret = 1;
      continue;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x36>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x1,%al
cmp    -0x8(%rbp),%ecx
mov    %al,-0x25(%rbp)
jl     11b0 <main+0x60>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11c0 <main+0x70>
jmp    12a9 <main+0x159>
cmpq   $0x0,-0x18(%rbp)
jne    1220 <main+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe22(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ff <main+0xaf>
mov    0x2df5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121b <main+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1220 <main+0xd0>
cmpq   $0x0,-0x18(%rbp)
jne    1243 <main+0xf3>
lea    0xdd2(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    1293 <main+0x143>
mov    -0x18(%rbp),%rdi
call   1030 <rev@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d8e(%rip),%rcx
cmp    (%rcx),%rax
je     126c <main+0x11c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jge    128e <main+0x13e>
lea    0xd87(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    1293 <main+0x143>
jmp    1293 <main+0x143>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    1194 <main+0x44>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x2e80(%rip),%rax
mov    (%rax),%rbp
cmp    $0x1,%edi
jg     117d <main+0x2d>
movl   $0x0,0x4(%rsp)
test   %rbp,%rbp
je     11fc <main+0xac>
cmp    $0x3,%r15d
mov    $0x2,%r12d
cmovge %r15d,%r12d
cmp    $0x1,%r15d
jg     1196 <main+0x46>
test   %rbp,%rbp
jne    11c8 <main+0x78>
mov    0x8(%rbx),%r13
lea    0xe5f(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11bf <main+0x6f>
lea    0xe4e(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
je     12a5 <main+0x155>
mov    %rbp,%rdi
call   1030 <rev@plt>
mov    %eax,%r13d
mov    0x2e0e(%rip),%rax
cmp    (%rax),%rbp
je     11e7 <main+0x97>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
test   %r13d,%r13d
js     12a5 <main+0x155>
mov    %eax,0x4(%rsp)
cmp    $0x3,%r15d
jge    120f <main+0xbf>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2,%r14d
lea    0xde4(%rip),%r13
jmp    122e <main+0xde>
xchg   %ax,%ax
test   %r15d,%r15d
js     128f <main+0x13f>
add    $0x1,%r14
cmp    %r14,%r12
je     11fc <main+0xac>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1280 <main+0x130>
mov    %rbp,%rdi
lea    0xdb7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
je     128f <main+0x13f>
mov    %rbp,%rdi
call   1030 <rev@plt>
mov    %eax,%r15d
mov    0x2d7e(%rip),%rax
cmp    (%rax),%rbp
je     1220 <main+0xd0>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    1220 <main+0xd0>
nopl   0x0(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%rbp
test   %rbp,%rbp
jne    1258 <main+0x108>
lea    0xd6e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,0x4(%rsp)
jmp    1225 <main+0xd5>
lea    0xd58(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11f2 <main+0xa2>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"rev\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** @stdin
store i32* %13, i32** %6
br label %14
14: ; preds = %12, %2
store i32 0, i32* %8
store i32 1, i32* %7
br label %15
15: ; preds = %65, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br label %22
22: ; preds = %19, %15
%23 = phi i1 [ true, %15 ], [ %21, %19 ]
br i1 %23, label %24, label %68
24: ; preds = %22
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %45, label %27
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = load i32*, i32** @stdin
store i32* %36, i32** %6
br label %44
37: ; preds = %27
%38 = load i8**, i8*** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %6
br label %44
44: ; preds = %37, %35
br label %45
45: ; preds = %44, %24
%46 = load i32*, i32** %6
%47 = icmp ne i32* %46, null
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %65
50: ; preds = %45
%51 = load i32*, i32** %6
%52 = call i32 @rev(i32* %51)
store i32 %52, i32* %9
%53 = load i32*, i32** %6
%54 = load i32*, i32** @stdin
%55 = icmp ne i32* %53, %54
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %56, %50
%60 = load i32, i32* %9
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %65
64: ; preds = %59
br label %65
65: ; preds = %64, %62, %48
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
store i32* null, i32** %6
br label %15
68: ; preds = %22
%69 = load i32, i32* %8
ret i32 %69
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"rev\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = icmp sgt i32 %0, 1
%5 = icmp ne i32* %3, null
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %7, label %64
7: ; preds = %2
%8 = icmp slt i32 %0, 2
%9 = select i1 %8, i1 %5, i1 false
%10 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%11 = zext i32 %10 to i64
br i1 %9, label %22, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %12, %17
%20 = phi i32* [ %18, %17 ], [ %3, %12 ]
%21 = icmp eq i32* %20, null
br i1 %21, label %31, label %22
22: ; preds = %19, %7
%23 = phi i32* [ %20, %19 ], [ %3, %7 ]
%24 = tail call i32 @rev(i32* %23)
%25 = load i32*, i32** @stdin
%26 = icmp eq i32* %23, %25
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = tail call i32 @fclose(i32* %23)
br label %29
29: ; preds = %27, %22
%30 = icmp slt i32 %24, 0
br i1 %30, label %31, label %33
31: ; preds = %29, %19
%32 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = phi i32 [ 0, %29 ], [ 1, %31 ]
%35 = icmp slt i32 %0, 3
br i1 %35, label %64, label %36
36: ; preds = %33, %60
%37 = phi i64 [ %62, %60 ], [ 2, %33 ]
%38 = phi i32 [ %61, %60 ], [ %34, %33 ]
%39 = getelementptr inbounds i8*, i8** %1, i64 %37
%40 = load i8*, i8** %39
%41 = tail call i32 @strcmp(i8* dereferenceable(1) %40, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = load i32*, i32** @stdin
br label %47
45: ; preds = %36
%46 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %43, %45
%48 = phi i32* [ %46, %45 ], [ %44, %43 ]
%49 = icmp eq i32* %48, null
br i1 %49, label %58, label %50
50: ; preds = %47
%51 = tail call i32 @rev(i32* %48)
%52 = load i32*, i32** @stdin
%53 = icmp eq i32* %48, %52
br i1 %53, label %56, label %54
54: ; preds = %50
%55 = tail call i32 @fclose(i32* %48)
br label %56
56: ; preds = %54, %50
%57 = icmp slt i32 %51, 0
br i1 %57, label %58, label %60
58: ; preds = %56, %47
%59 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
%61 = phi i32 [ %38, %56 ], [ 1, %58 ]
%62 = add nuw nsw i64 %37, 1
%63 = icmp eq i64 %62, %11
br i1 %63, label %64, label %36
64: ; preds = %60, %33, %2
%65 = phi i32 [ 0, %2 ], [ %34, %33 ], [ %61, %60 ]
ret i32 %65
}