#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*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ rt_ui_message(int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int createtgafile(char *name, unsigned short width, unsigned short height) {
  int filesize;
  FILE *ofp;
  filesize = 3 * width * height + 18 - 10;
  if (name == NULL) {
    return 5;
  } else {
    ofp = fopen(name, "w+b");
    if (ofp == NULL) {
      char msgtxt[2048];
      sprintf(msgtxt, "Cannot create %s for output!", name);
      rt_ui_message(200, msgtxt);
      rt_ui_message(300, "Rendering Aborted.");
      return 5;
    }
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(2, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc(0, ofp);
    fputc((width & 0xff), ofp);
    fputc(((width >> 8) & 0xff), ofp);
    fputc((height & 0xff), ofp);
    fputc(((height >> 8) & 0xff), ofp);
    fputc(24, ofp);
    fputc(0x20, ofp);
    fseek(ofp, filesize, 0);
    fprintf(ofp, "9876543210");
    fclose(ofp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<createtgafile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %rdi,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
movzwl -0x12(%rbp),%eax
imul   $0x3,%eax,%eax
movzwl -0x14(%rbp),%ecx
imul   %ecx,%eax
add    $0x12,%eax
sub    $0xa,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <createtgafile+0x4b>
movl   $0x5,-0x4(%rbp)
jmp    1342 <createtgafile+0x1d2>
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121f <createtgafile+0xaf>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x820(%rbp),%rsi
mov    $0xc8,%edi
call   1030 <rt_ui_message@plt>
mov    $0x12c,%edi
lea    0xe13(%rip),%rsi
call   1030 <rt_ui_message@plt>
movl   $0x5,-0x4(%rbp)
jmp    1342 <createtgafile+0x1d2>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x2,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
movzwl -0x12(%rbp),%edi
and    $0xff,%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
movzwl -0x12(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
movzwl -0x14(%rbp),%edi
and    $0xff,%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
movzwl -0x14(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x18,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x20,%edi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createtgafile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    $0x5,%r14d
test   %rdi,%rdi
je     12f1 <createtgafile+0x181>
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbp
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12be <createtgafile+0x14e>
mov    %rax,%rbx
mov    %r13d,%eax
imul   %r12d,%eax
lea    (%rax,%rax,2),%r15d
add    $0x8,%r15d
xor    %r14d,%r14d
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
movzbl %r13b,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
shr    $0x8,%r13d
mov    %r13d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
movzbl %r12b,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
shr    $0x8,%r12d
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x18,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %edx,%edx
call   1060 <fseek@plt>
lea    0xd92(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    12f1 <createtgafile+0x181>
lea    0xd3f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
mov    $0xc8,%edi
mov    %rbx,%rsi
call   1030 <rt_ui_message@plt>
lea    0xd3a(%rip),%rsi
mov    $0x12c,%edi
call   1030 <rt_ui_message@plt>
mov    %r14d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"w+b\00"
@.str.1 = [29 x i8] c"Cannot create %s for output!\00"
@.str.2 = [19 x i8] c"Rendering Aborted.\00"
@.str.3 = [11 x i8] c"9876543210\00"
define i32 @createtgafile(i8* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [2048 x i8]
store i8* %0, i8** %5
store i16 %1, i16* %6
store i16 %2, i16* %7
%11 = load i16, i16* %6
%12 = zext i16 %11 to i32
%13 = mul nsw i32 3, %12
%14 = load i16, i16* %7
%15 = zext i16 %14 to i32
%16 = mul nsw i32 %13, %15
%17 = add nsw i32 %16, 18
%18 = sub nsw i32 %17, 10
store i32 %18, i32* %8
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 5, i32* %4
br label %93
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %9
%25 = load i32*, i32** %9
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%32 = call i32 @rt_ui_message(i32 200, i8* %31)
%33 = call i32 @rt_ui_message(i32 300, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 5, i32* %4
br label %93
34: ; preds = %22
%35 = load i32*, i32** %9
%36 = call i32 @fputc(i32 0, i32* %35)
%37 = load i32*, i32** %9
%38 = call i32 @fputc(i32 0, i32* %37)
%39 = load i32*, i32** %9
%40 = call i32 @fputc(i32 2, i32* %39)
%41 = load i32*, i32** %9
%42 = call i32 @fputc(i32 0, i32* %41)
%43 = load i32*, i32** %9
%44 = call i32 @fputc(i32 0, i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fputc(i32 0, i32* %45)
%47 = load i32*, i32** %9
%48 = call i32 @fputc(i32 0, i32* %47)
%49 = load i32*, i32** %9
%50 = call i32 @fputc(i32 0, i32* %49)
%51 = load i32*, i32** %9
%52 = call i32 @fputc(i32 0, i32* %51)
%53 = load i32*, i32** %9
%54 = call i32 @fputc(i32 0, i32* %53)
%55 = load i32*, i32** %9
%56 = call i32 @fputc(i32 0, i32* %55)
%57 = load i32*, i32** %9
%58 = call i32 @fputc(i32 0, i32* %57)
%59 = load i16, i16* %6
%60 = zext i16 %59 to i32
%61 = and i32 %60, 255
%62 = load i32*, i32** %9
%63 = call i32 @fputc(i32 %61, i32* %62)
%64 = load i16, i16* %6
%65 = zext i16 %64 to i32
%66 = ashr i32 %65, 8
%67 = and i32 %66, 255
%68 = load i32*, i32** %9
%69 = call i32 @fputc(i32 %67, i32* %68)
%70 = load i16, i16* %7
%71 = zext i16 %70 to i32
%72 = and i32 %71, 255
%73 = load i32*, i32** %9
%74 = call i32 @fputc(i32 %72, i32* %73)
%75 = load i16, i16* %7
%76 = zext i16 %75 to i32
%77 = ashr i32 %76, 8
%78 = and i32 %77, 255
%79 = load i32*, i32** %9
%80 = call i32 @fputc(i32 %78, i32* %79)
%81 = load i32*, i32** %9
%82 = call i32 @fputc(i32 24, i32* %81)
%83 = load i32*, i32** %9
%84 = call i32 @fputc(i32 32, i32* %83)
%85 = load i32*, i32** %9
%86 = load i32, i32* %8
%87 = call i32 @fseek(i32* %85, i32 %86, i32 0)
%88 = load i32*, i32** %9
%89 = call i32 @fprintf(i32* %88, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%90 = load i32*, i32** %9
%91 = call i32 @fclose(i32* %90)
br label %92
92: ; preds = %34
store i32 0, i32* %4
br label %93
93: ; preds = %92, %27, %21
%94 = load i32, i32* %4
ret i32 %94
}

LLVM IR (-O2):
@.str = [4 x i8] c"w+b\00"
@.str.1 = [29 x i8] c"Cannot create %s for output!\00"
@.str.2 = [19 x i8] c"Rendering Aborted.\00"
@.str.3 = [11 x i8] c"9876543210\00"
define i32 @createtgafile(i8* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca [2048 x i8]
%5 = zext i16 %1 to i32
%6 = mul nuw nsw i32 %5, 3
%7 = zext i16 %2 to i32
%8 = mul nsw i32 %6, %7
%9 = add nuw nsw i32 %8, 8
%10 = icmp eq i8* %0, null
br i1 %10, label %45, label %11
11: ; preds = %3
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = call i32 @rt_ui_message(i32 200, i8* %15)
%18 = call i32 @rt_ui_message(i32 300, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %45
19: ; preds = %11
%20 = tail call i32 @fputc(i32 0, i32* %12)
%21 = tail call i32 @fputc(i32 0, i32* %12)
%22 = tail call i32 @fputc(i32 2, i32* %12)
%23 = tail call i32 @fputc(i32 0, i32* %12)
%24 = tail call i32 @fputc(i32 0, i32* %12)
%25 = tail call i32 @fputc(i32 0, i32* %12)
%26 = tail call i32 @fputc(i32 0, i32* %12)
%27 = tail call i32 @fputc(i32 0, i32* %12)
%28 = tail call i32 @fputc(i32 0, i32* %12)
%29 = tail call i32 @fputc(i32 0, i32* %12)
%30 = tail call i32 @fputc(i32 0, i32* %12)
%31 = tail call i32 @fputc(i32 0, i32* %12)
%32 = and i32 %5, 255
%33 = tail call i32 @fputc(i32 %32, i32* %12)
%34 = lshr i32 %5, 8
%35 = tail call i32 @fputc(i32 %34, i32* %12)
%36 = and i32 %7, 255
%37 = tail call i32 @fputc(i32 %36, i32* %12)
%38 = lshr i32 %7, 8
%39 = tail call i32 @fputc(i32 %38, i32* %12)
%40 = tail call i32 @fputc(i32 24, i32* %12)
%41 = tail call i32 @fputc(i32 32, i32* %12)
%42 = tail call i32 @fseek(i32* %12, i32 %9, i32 0)
%43 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 10, i64 1, i32* %12)
%44 = tail call i32 @fclose(i32* %12)
br label %45
45: ; preds = %3, %19, %14
%46 = phi i32 [ 5, %14 ], [ 0, %19 ], [ 5, %3 ]
ret i32 %46
}