#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 */
scalar_t__ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc >= 2 && strcmp(argv[1], "--close") == 0) {
    fprintf(stdout, "Closing file handles!\n");
    int rc = 0;
    if (fclose(stdin) != 0) {
      rc += 1;
    }
    if (fclose(stdout) != 0) {
      rc += 2;
    }
    if (fclose(stderr) != 0) {
      rc += 4;
    }
    return rc;
  } else {
    fprintf(stdout, "Not doing anything.\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11f8 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea1(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f8 <main+0xc8>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11ab <main+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11cc <main+0x9c>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11ed <main+0xbd>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <main+0xe4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     114e <main+0x1e>
mov    0x8(%rsi),%rdi
lea    0xebc(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1167 <main+0x37>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
jmp    11c2 <main+0x92>
mov    0x2e62(%rip),%r14
mov    (%r14),%edi
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    (%r14),%edi
call   1030 <fclose@plt>
lea    0x2(%rbx),%r14d
test   %rax,%rax
cmove  %ebx,%r14d
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    %rax,%rcx
lea    0x4(%r14),%eax
test   %rcx,%rcx
cmove  %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"--close\00"
@stdout = global i32 0
@.str.1 = [23 x i8] c"Closing file handles!\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [21 x i8] c"Not doing anything.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %4
%10 = load i32, i32* @stdout
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = tail call i64 @fclose(i32 %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
%16 = load i32, i32* @stdout
%17 = tail call i64 @fclose(i32 %16)
%18 = icmp eq i64 %17, 0
%19 = or i32 %15, 2
%20 = select i1 %18, i32 %15, i32 %19
%21 = load i32, i32* @stderr
%22 = tail call i64 @fclose(i32 %21)
%23 = icmp eq i64 %22, 0
%24 = or i32 %20, 4
%25 = select i1 %23, i32 %20, i32 %24
br label %29
26: ; preds = %4, %2
%27 = load i32, i32* @stdout
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %9
%30 = phi i32 [ %25, %9 ], [ 0, %26 ]
ret i32 %30
}