#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*/ bake_args(int, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fold_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  bake_args(argc, argv);
  FILE *file = NULL;
  if (argc == optind)
    file = stdin;
  int i, ret = 0;
  for (i = optind; i < argc || file; i++, file = NULL) {
    if (!file) {
      if (!strcmp(argv[i], "-"))
        file = stdin;
      else
        file = fopen(argv[i], "r");
    }
    if (!file) {
      perror("fold");
      ret = 1;
      continue;
    }
    int err = fold_file(file);
    if (file != stdin)
      fclose(file);
    if (err < 0) {
      perror("fold");
      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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <bake_args@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%eax
jne    11aa <main+0x4a>
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x1,%al
cmp    -0x8(%rbp),%ecx
mov    %al,-0x25(%rbp)
jl     11d9 <main+0x79>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11e9 <main+0x89>
jmp    12d2 <main+0x172>
cmpq   $0x0,-0x18(%rbp)
jne    1249 <main+0xe9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1228 <main+0xc8>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1244 <main+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdc7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1249 <main+0xe9>
cmpq   $0x0,-0x18(%rbp)
jne    126c <main+0x10c>
lea    0xda9(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    12bc <main+0x15c>
mov    -0x18(%rbp),%rdi
call   1040 <fold_file@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d65(%rip),%rcx
cmp    (%rcx),%rax
je     1295 <main+0x135>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jge    12b7 <main+0x157>
lea    0xd5e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x20(%rbp)
jmp    12bc <main+0x15c>
jmp    12bc <main+0x15c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    11bd <main+0x5d>
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,%ebp
call   1080 <bake_args@plt>
mov    0x2e64(%rip),%rax
movslq (%rax),%r14
cmp    %ebp,%r14d
sete   %cl
mov    0x2e5c(%rip),%rax
mov    (%rax),%r15
test   %r15,%r15
setne  %al
and    %cl,%al
cmp    %ebp,%r14d
jl     11ac <main+0x4c>
movl   $0x0,0x4(%rsp)
test   %al,%al
je     12b5 <main+0x155>
movslq %ebp,%r12
test   %al,%al
jne    11e5 <main+0x85>
mov    (%rbx,%r14,8),%rbp
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11dc <main+0x7c>
lea    0xe31(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %r15,%r15
je     12c8 <main+0x168>
mov    %r15,%rdi
call   1040 <fold_file@plt>
mov    %eax,%ebp
mov    0x2df2(%rip),%rax
cmp    (%rax),%r15
je     1203 <main+0xa3>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
test   %ebp,%ebp
js     12c8 <main+0x168>
mov    %eax,0x4(%rsp)
add    $0x1,%r14
cmp    %r12,%r14
jge    12b5 <main+0x155>
lea    0xddb(%rip),%r13
jmp    123e <main+0xde>
nopw   0x0(%rax,%rax,1)
test   %r15d,%r15d
js     129f <main+0x13f>
add    $0x1,%r14
cmp    %r12,%r14
jge    12b5 <main+0x155>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1290 <main+0x130>
mov    %rbp,%rdi
lea    0xda7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
je     129f <main+0x13f>
mov    %rbp,%rdi
call   1040 <fold_file@plt>
mov    %eax,%r15d
mov    0x2d6e(%rip),%rax
cmp    (%rax),%rbp
je     1230 <main+0xd0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    1230 <main+0xd0>
nopl   0x0(%rax)
mov    0x2d51(%rip),%rax
mov    (%rax),%rbp
test   %rbp,%rbp
jne    1268 <main+0x108>
lea    0xd5e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,0x4(%rsp)
jmp    1235 <main+0xd5>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd35(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    120d <main+0xad>

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

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