#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 /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char *const *, char *);
int optind;
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ rip(int /*<<< orphan*/, int /*<<< orphan*/, int);
int rip_file(char *const, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *const *argv) {
  int c;
  int comment = 0;
  int main_loop = 0;
  while ((c = getopt(argc, argv, "chi:o:")) != -1) {
    switch (c) {
    case 'h':
      print_help();
      break;
    case 'c':
      comment = 1;
      break;
    }
  }
  int index;
  int r = 0;
  for (index = optind; index < argc; index++) {
    main_loop = 1;
    if ((r = rip_file(argv[index], comment)) != 0) {
      fprintf(stderr, "Error occured while processing file %s.\n", argv[index]);
    };
  }
  if (!main_loop) {
    rip(stdin, stdout, comment);
    if (ferror(stdin) || ferror(stdout)) {
      fprintf(stderr, "Error occured while processing the file.\n");
      exit(1);
    }
  }
  exit(r);
}


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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11f0 <main+0x80>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x63,%eax
je     11e4 <main+0x74>
jmp    11c7 <main+0x57>
mov    -0x28(%rbp),%eax
sub    $0x68,%eax
jne    11eb <main+0x7b>
jmp    11d8 <main+0x68>
mov    $0x0,%al
call   1080 <print_help@plt>
jmp    11eb <main+0x7b>
movl   $0x1,-0x18(%rbp)
jmp    1194 <main+0x24>
movl   $0x0,-0x24(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126c <main+0xfc>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
call   1040 <rip_file@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1259 <main+0xe9>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    125e <main+0xee>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1203 <main+0x93>
cmpl   $0x0,-0x1c(%rbp)
jne    12e6 <main+0x176>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
call   1060 <rip@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    12c0 <main+0x150>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12e1 <main+0x171>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12e6 <main+0x176>
mov    -0x24(%rbp),%edi
call   1090 <exit@plt>

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
lea    0xe79(%rip),%r15
xor    %r14d,%r14d
jmp    11a0 <main+0x30>
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x68,%eax
je     11c0 <main+0x50>
cmp    $0x63,%eax
je     118c <main+0x1c>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x30>
jmp    11c9 <main+0x59>
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <print_help@plt>
jmp    11a0 <main+0x30>
mov    0x2e10(%rip),%rax
movslq (%rax),%rax
xor    %r15d,%r15d
cmp    %ebp,%eax
jge    122e <main+0xbe>
lea    (%rbx,%rax,8),%rbx
mov    %ebp,%r12d
mov    %rax,(%rsp)
sub    %eax,%r12d
xor    %r13d,%r13d
jmp    11f9 <main+0x89>
nopl   (%rax)
add    $0x1,%r13
cmp    %r13d,%r12d
je     1229 <main+0xb9>
mov    (%rbx,%r13,8),%rdi
mov    %r14d,%esi
call   1040 <rip_file@plt>
mov    %eax,%r15d
test   %eax,%eax
je     11f0 <main+0x80>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r13,8),%rdx
lea    0xde7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11f0 <main+0x80>
cmp    %ebp,(%rsp)
jl     1262 <main+0xf2>
mov    0x2db3(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d89(%rip),%rbx
mov    (%rbx),%esi
mov    %r14d,%edx
call   1060 <rip@plt>
mov    0x0(%rbp),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    126a <main+0xfa>
mov    (%rbx),%edi
call   1030 <ferror@plt>
test   %rax,%rax
jne    126a <main+0xfa>
mov    %r15d,%edi
call   1090 <exit@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"chi:o:\00"
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Error occured while processing file %s.\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [42 x i8] c"Error occured while processing the file.\0A\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %21, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %21 [
i32 104, label %18
i32 99, label %20
]
18: ; preds = %16
%19 = call i32 (...) @print_help()
br label %21
20: ; preds = %16
store i32 1, i32* %7
br label %21
21: ; preds = %16, %20, %18
br label %11
22: ; preds = %11
store i32 0, i32* %10
%23 = load i32, i32* @optind
store i32 %23, i32* %9
br label %24
24: ; preds = %46, %22
%25 = load i32, i32* %9
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %49
28: ; preds = %24
store i32 1, i32* %8
%29 = load i8**, i8*** %5
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* %7
%35 = call i32 @rip_file(i8* %33, i32 %34)
store i32 %35, i32* %10
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %28
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %37, %28
br label %46
46: ; preds = %45
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %24
49: ; preds = %24
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %69, label %52
52: ; preds = %49
%53 = load i32, i32* @stdin
%54 = load i32, i32* @stdout
%55 = load i32, i32* %7
%56 = call i32 @rip(i32 %53, i32 %54, i32 %55)
%57 = load i32, i32* @stdin
%58 = call i64 @ferror(i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %52
%61 = load i32, i32* @stdout
%62 = call i64 @ferror(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %60, %52
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %60
br label %69
69: ; preds = %68, %49
%70 = load i32, i32* %10
%71 = call i32 @exit(i32 %70)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"chi:o:\00"
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Error occured while processing file %s.\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [42 x i8] c"Error occured while processing the file.\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %5, %2
%4 = phi i32 [ 0, %2 ], [ 1, %5 ]
br label %5
5: ; preds = %7, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %7 [
i32 -1, label %10
i32 104, label %8
i32 99, label %3
]
7: ; preds = %5, %8
br label %5
8: ; preds = %5
%9 = tail call i32 (...) @print_help()
br label %7
10: ; preds = %5
%11 = load i32, i32* @optind
%12 = icmp slt i32 %11, %0
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = sext i32 %11 to i64
br label %15
15: ; preds = %13, %25
%16 = phi i64 [ %14, %13 ], [ %26, %25 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @rip_file(i8* %18, i32 %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %17
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %15, %21
%26 = add nsw i64 %16, 1
%27 = trunc i64 %26 to i32
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %15
29: ; preds = %25
br i1 %12, label %46, label %30
30: ; preds = %10, %29
%31 = phi i32 [ %19, %29 ], [ 0, %10 ]
%32 = load i32, i32* @stdin
%33 = load i32, i32* @stdout
%34 = tail call i32 @rip(i32 %32, i32 %33, i32 %4)
%35 = load i32, i32* @stdin
%36 = tail call i64 @ferror(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i32, i32* @stdout
%40 = tail call i64 @ferror(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38, %30
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %38, %29
%47 = phi i32 [ %31, %38 ], [ %19, %29 ]
%48 = tail call i32 @exit(i32 %47)
unreachable
}