#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 handle_msg(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int main(int argc, char **argv) {
  FILE *input_stream = NULL;
  if (argc == 2) {
    char *input_path = argv[1];
    if (!(input_stream = fopen(input_path, "rb")))
      return 5;
  } else if (argc == 1)
    input_stream = stdin;
  else
    return 10;
  int err;
  while ((err = handle_msg(input_stream)) == -1)
    ;
  if (input_stream != stdin)
    fclose(input_stream);
  return err;
}


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)
jne    1193 <main+0x63>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118e <main+0x5e>
movl   $0x5,-0x4(%rbp)
jmp    1203 <main+0xd3>
jmp    11c1 <main+0x91>
cmpl   $0x1,-0x8(%rbp)
jne    11b0 <main+0x80>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <main+0x8c>
movl   $0xa,-0x4(%rbp)
jmp    1203 <main+0xd3>
jmp    11c1 <main+0x91>
jmp    11c6 <main+0x96>
mov    -0x18(%rbp),%rdi
call   1040 <handle_msg@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11e0 <main+0xb0>
jmp    11c6 <main+0x96>
mov    -0x18(%rbp),%rax
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
je     11fd <main+0xcd>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
je     1162 <main+0x32>
mov    $0xa,%ebx
cmp    $0x2,%edi
jne    1193 <main+0x63>
mov    0x8(%rsi),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1170 <main+0x40>
mov    $0x5,%ebx
jmp    1193 <main+0x63>
mov    0x2e7f(%rip),%rax
mov    (%rax),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <handle_msg@plt>
cmp    $0xffffffff,%eax
je     1170 <main+0x40>
mov    %eax,%ebx
mov    0x2e62(%rip),%rax
cmp    (%rax),%r14
je     1193 <main+0x63>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %11
store i32 5, i32* %3
br label %42
19: ; preds = %11
br label %27
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32*, i32** @stdin
store i32* %24, i32** %6
br label %26
25: ; preds = %20
store i32 10, i32* %3
br label %42
26: ; preds = %23
br label %27
27: ; preds = %26, %19
br label %28
28: ; preds = %32, %27
%29 = load i32*, i32** %6
%30 = call i32 @handle_msg(i32* %29)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %28
br label %28
33: ; preds = %28
%34 = load i32*, i32** %6
%35 = load i32*, i32** @stdin
%36 = icmp ne i32* %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %33
%41 = load i32, i32* %8
store i32 %41, i32* %3
br label %42
42: ; preds = %40, %25, %18
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %20 [
i32 2, label %3
i32 1, label %8
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %20, label %10
8: ; preds = %2
%9 = load i32*, i32** @stdin
br label %10
10: ; preds = %3, %8
%11 = phi i32* [ %6, %3 ], [ %9, %8 ]
br label %12
12: ; preds = %12, %10
%13 = tail call i32 @handle_msg(i32* %11)
%14 = icmp eq i32 %13, -1
br i1 %14, label %12, label %15
15: ; preds = %12
%16 = load i32*, i32** @stdin
%17 = icmp eq i32* %11, %16
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @fclose(i32* %11)
br label %20
20: ; preds = %15, %18, %2, %3
%21 = phi i32 [ 5, %3 ], [ 10, %2 ], [ %13, %18 ], [ %13, %15 ]
ret i32 %21
}