#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stderr;
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "usage: diamondc input.coal output.diamond");
    return 1;
  }
  FILE *in = fopen(argv[1], "r");
  if (in) {
    fclose(in);
  } else {
    return 1;
  }
  FILE *out = fopen(argv[2], "w");
  if (out) {
    fprintf(out, "diamond\n");
    fclose(out);
  } else {
    return 1;
  }
  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   $0x3,-0x8(%rbp)
jge    1172 <main+0x42>
mov    0x2e89(%rip),%rax
mov    (%rax),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1203 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a3 <main+0x73>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11af <main+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    1203 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f0 <main+0xc0>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11fc <main+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    1203 <main+0xd3>
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
jg     1160 <main+0x30>
mov    0x2ea0(%rip),%rax
mov    (%rax),%rcx
lea    0xeb6(%rip),%rdi
mov    $0x29,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    $0x1,%ebx
jmp    11c0 <main+0x90>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xebc(%rip),%rsi
call   1040 <fopen@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11c0 <main+0x90>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11c0 <main+0x90>
mov    %rax,%r14
lea    0xe8a(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@stderr = global i32* null
@.str = [42 x i8] c"usage: diamondc input.coal output.diamond\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"diamond\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 41, i64 1, i32* %5)
br label %21
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %10)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 8, i64 1, i32* %16)
%20 = tail call i32 @fclose(i32* %16)
br label %21
21: ; preds = %7, %12, %18, %4
%22 = phi i32 [ 1, %4 ], [ 1, %7 ], [ 0, %18 ], [ 1, %12 ]
ret i32 %22
}