#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ pack_wordimage_copen(short *, int, int,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void pack_wordimage_c(short int *img, int x, int y, char *filename) {
  FILE *packfile = fopen(filename, "a");
  if (packfile == NULL) {
    fprintf(stderr, "The file %s cannot be created!\n   ...giving up...\n",
            filename);
    exit(1);
  } else {
    pack_wordimage_copen(img, x, y, packfile);
    fclose(packfile);
  }
}


x86 assembly (clang, -O0):
<pack_wordimage_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <pack_wordimage_c+0x58>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1050 <pack_wordimage_copen@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_wordimage_c>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0xe95(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <pack_wordimage_c+0x4c>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1050 <pack_wordimage_copen@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"The file %s cannot be created!\0A ...giving up...\0A\00"
define void @pack_wordimage_c(i16* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i16*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i16* %0, i16** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %8
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %4
%20 = load i16*, i16** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = load i32*, i32** %9
%24 = call i32 @pack_wordimage_copen(i16* %20, i32 %21, i32 %22, i32* %23)
%25 = load i32*, i32** %9
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"The file %s cannot be created!\0A ...giving up...\0A\00"
define void @pack_wordimage_c(i16* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = tail call i32 @pack_wordimage_copen(i16* %0, i32 %1, i32 %2, i32* %5)
%13 = tail call i32 @fclose(i32* %5)
ret void
}