#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 EXIT_FAILURE;
int assemblage(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  FILE *fdi, *fdo;
  if (argc != 3) {
    usage(stderr, argv[0]);
    return EXIT_FAILURE;
  }
  if ((fdi = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Error opening file %s: %s\n", argv[1], strerror(errno));
    return EXIT_FAILURE;
  }
  if ((fdo = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "Error opening file %s: %s\n", argv[2], strerror(errno));
    return EXIT_FAILURE;
  }
  const int r = assemblage(fdi, fdo, stderr);
  fclose(fdi);
  fclose(fdo);
  return r;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1050 <usage@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1215 <main+0xb5>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe03(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1284 <main+0x124>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd94(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <main+0x155>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2d4d(%rip),%rax
mov    (%rax),%edx
call   1060 <assemblage@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11cb <main+0x6b>
mov    0x8(%rbx),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11de <main+0x7e>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    0x2e3f(%rip),%rax
mov    (%rax),%ebp
test   %r15,%r15
je     11ed <main+0x8d>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <assemblage@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    121c <main+0xbc>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rsi
call   1050 <usage@plt>
jmp    1213 <main+0xb3>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
jmp    11f1 <main+0x91>
mov    0x10(%rbx),%rbx
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdfc(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Error opening file %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"wb\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i32 %12, i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %58
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %33
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %3
br label %58
33: ; preds = %18
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %37, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %48
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %3
br label %58
48: ; preds = %33
%49 = load i32*, i32** %6
%50 = load i32*, i32** %7
%51 = load i32, i32* @stderr
%52 = call i32 @assemblage(i32* %49, i32* %50, i32 %51)
store i32 %52, i32* %8
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* %8
store i32 %57, i32* %3
br label %58
58: ; preds = %48, %39, %24, %11
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Error opening file %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i32 %5, i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
br label %37
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
br label %37
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
%26 = load i32, i32* @stderr
br i1 %25, label %27, label %33
27: ; preds = %21
%28 = load i8*, i8** %22
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %37
33: ; preds = %21
%34 = tail call i32 @assemblage(i32* %12, i32* %24, i32 %26)
%35 = tail call i32 @fclose(i32* %12)
%36 = tail call i32 @fclose(i32* %24)
br label %37
37: ; preds = %33, %27, %14, %4
%38 = phi i32 [ %8, %4 ], [ %20, %14 ], [ %32, %27 ], [ %34, %33 ]
ret i32 %38
}