#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*/ DoubleWords(char const *, int /*<<< orphan*/ *);
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
char *strerror(int /*<<< orphan*/);
int DoubleMain(int argc, const char **argv) {
  if (argc == 1) {
    DoubleWords(NULL, stdin);
    return EXIT_SUCCESS;
  }
  for (int i = 1; i < argc; i++) {
    const char *fileName = argv[i];
    FILE *fp = fopen(fileName, "r");
    if (fp == NULL) {
      fprintf(stderr, "cannot open: %s, reason: %s\n", fileName,
              strerror(errno));
      return EXIT_FAILURE;
    }
    DoubleWords(argv[i], fp);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<DoubleMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    117d <DoubleMain+0x3d>
mov    0x2e88(%rip),%rax
mov    (%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <DoubleWords@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <DoubleMain+0xf7>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122b <DoubleMain+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1208 <DoubleMain+0xc8>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe10(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <DoubleMain+0xf7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <DoubleWords@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <DoubleMain+0x44>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoubleMain>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jne    1163 <DoubleMain+0x23>
mov    0x2e94(%rip),%rax
mov    (%rax),%rsi
xor    %edi,%edi
call   1030 <DoubleWords@plt>
jmp    1215 <DoubleMain+0xd5>
jle    1215 <DoubleMain+0xd5>
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rbx
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d7 <DoubleMain+0x97>
mov    %ebp,%r12d
mov    $0x2,%ebp
lea    0xe6b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x8(%r14,%rbp,8),%rdi
mov    %rax,%rsi
call   1030 <DoubleWords@plt>
cmp    %rbp,%r12
je     1213 <DoubleMain+0xd3>
mov    (%r14,%rbp,8),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    11a0 <DoubleMain+0x60>
add    $0xffffffffffffffff,%rbp
cmp    %r12,%rbp
setb   %r14b
jmp    11da <DoubleMain+0x9a>
mov    $0x1,%r14b
mov    0x2df7(%rip),%rax
mov    (%rax),%ebp
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe0a(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
test   %r14b,%r14b
je     1215 <DoubleMain+0xd5>
mov    0x2db7(%rip),%rax
jmp    121c <DoubleMain+0xdc>
ja     121e <DoubleMain+0xde>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"cannot open: %s, reason: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @DoubleMain(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* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32*, i32** @stdin
%13 = call i32 @DoubleWords(i8* null, i32* %12)
%14 = load i32, i32* @EXIT_SUCCESS
store i32 %14, i32* %3
br label %50
15: ; preds = %2
store i32 1, i32* %6
br label %16
16: ; preds = %45, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %48
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %37
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %7
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %3
br label %50
37: ; preds = %20
%38 = load i8**, i8*** %5
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = load i32*, i32** %8
%44 = call i32 @DoubleWords(i8* %42, i32* %43)
br label %45
45: ; preds = %37
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %16
48: ; preds = %16
%49 = load i32, i32* @EXIT_SUCCESS
store i32 %49, i32* %3
br label %50
50: ; preds = %48, %30, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stdin = global i32* null
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"cannot open: %s, reason: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @DoubleMain(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = load i32, i32* @EXIT_SUCCESS
br label %48
8: ; preds = %4
%9 = zext i32 %0 to i64
%10 = zext i32 %0 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %26, label %35
15: ; preds = %2
%16 = load i32*, i32** @stdin
%17 = tail call i32 @DoubleWords(i8* null, i32* %16)
%18 = load i32, i32* @EXIT_SUCCESS
br label %48
19: ; preds = %35
%20 = getelementptr inbounds i8*, i8** %1, i64 %41
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = icmp ult i64 %41, %9
br label %26
26: ; preds = %24, %8
%27 = phi i1 [ true, %8 ], [ %25, %24 ]
%28 = phi i8* [ %12, %8 ], [ %21, %24 ]
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = load i32, i32* @EXIT_SUCCESS
br i1 %27, label %46, label %48
35: ; preds = %8, %19
%36 = phi i32* [ %22, %19 ], [ %13, %8 ]
%37 = phi i8** [ %20, %19 ], [ %11, %8 ]
%38 = phi i64 [ %41, %19 ], [ 1, %8 ]
%39 = load i8*, i8** %37
%40 = tail call i32 @DoubleWords(i8* %39, i32* %36)
%41 = add nuw nsw i64 %38, 1
%42 = icmp eq i64 %41, %10
br i1 %42, label %43, label %19
43: ; preds = %35
%44 = icmp ult i64 %41, %9
%45 = load i32, i32* @EXIT_SUCCESS
br i1 %44, label %46, label %48
46: ; preds = %26, %43
%47 = phi i32 [ %33, %26 ], [ undef, %43 ]
br label %48
48: ; preds = %46, %43, %6, %26, %15
%49 = phi i32 [ %18, %15 ], [ %47, %46 ], [ %45, %43 ], [ %7, %6 ], [ %34, %26 ]
ret i32 %49
}