#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*/ ExitMessage(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned short);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
void WriteTmpFile(const char *filename, unsigned short id) {
  FILE *tmpfile;
  tmpfile = fopen(filename, "w");
  if (tmpfile) {
    fprintf(tmpfile, "%hu", id);
  } else {
    char errorMessage[101];
    snprintf(errorMessage, 101, "Couldn't open temp file: %s", filename);
    ExitMessage(errorMessage);
  }
  fclose(tmpfile);
}


x86 assembly (clang, -O0):
<WriteTmpFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <WriteTmpFile+0x4e>
mov    -0x18(%rbp),%rdi
lea    0xe72(%rip),%rsi
movzwl -0xa(%rbp),%edx
call   1050 <fprintf@plt>
jmp    11c0 <WriteTmpFile+0x70>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x65,%esi
lea    0xe54(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
call   1060 <ExitMessage@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteTmpFile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1185 <WriteTmpFile+0x35>
movzwl %bp,%edx
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fprintf@plt>
jmp    11a7 <WriteTmpFile+0x57>
lea    0xe7a(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x65,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <ExitMessage@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%hu\00"
@.str.2 = [28 x i8] c"Couldn't open temp file: %s\00"
define void @WriteTmpFile(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i32*
%6 = alloca [101 x i8]
store i8* %0, i8** %3
store i16 %1, i16* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = load i16, i16* %4
%14 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %13)
br label %21
15: ; preds = %2
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32 @snprintf(i8* %16, i32 101, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [101 x i8], [101 x i8]* %6, i64 0, i64 0
%20 = call i32 @ExitMessage(i8* %19)
br label %21
21: ; preds = %15, %11
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%hu\00"
@.str.2 = [28 x i8] c"Couldn't open temp file: %s\00"
define void @WriteTmpFile(i8* %0, i16 zeroext %1) {
%3 = alloca [101 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %1)
br label %12
8: ; preds = %2
%9 = getelementptr inbounds [101 x i8], [101 x i8]* %3, i64 0, i64 0
%10 = call i32 @snprintf(i8* %9, i32 101, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = call i32 @ExitMessage(i8* %9)
br label %12
12: ; preds = %8, %6
%13 = call i32 @fclose(i32* %4)
ret void
}