#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 uint64_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fwrite(int const *, int, int, int /*<<< orphan*/ *);
int tga_header24(uint16_t w, uint16_t h, uint16_t ox, uint16_t oy, FILE *fp) {
  int c;
  const uint64_t hdr1 = 0x20000;
  uint64_t hdr2;
  uint16_t hdr3 = 24;
  hdr2 = ((uint64_t)ox) | (((uint64_t)oy) << 16) | (((uint64_t)w) << 32) |
         (((uint64_t)h) << 48);
  if (fwrite(&hdr1, sizeof(uint64_t), 1, fp) != 1) {
    return -1;
  }
  if (fwrite(&hdr2, sizeof(uint64_t), 1, fp) != 1) {
    return -1;
  }
  if (fwrite(&hdr3, sizeof(uint16_t), 1, fp) != 1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tga_header24>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x20000,-0x28(%rbp)
movl   $0x18,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%edx
mov    $0x20,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0xc(%rbp),%edx
mov    $0x30,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
je     118c <tga_header24+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <tga_header24+0xdb>
mov    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
je     11b8 <tga_header24+0xa8>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <tga_header24+0xdb>
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
je     11e4 <tga_header24+0xd4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <tga_header24+0xdb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tga_header24>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
movl   $0x20000,0x10(%rsp)
movl   $0x18,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r8,%rcx
call   1030 <fwrite@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%eax
jne    1188 <tga_header24+0x78>
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
jne    1188 <tga_header24+0x78>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fwrite@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tga_header24(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32 131072, i32* %13
store i32 24, i32* %15
%16 = load i32, i32* %9
%17 = load i32, i32* %10
%18 = shl i32 %17, 16
%19 = or i32 %16, %18
%20 = load i32, i32* %7
%21 = shl i32 %20, 32
%22 = or i32 %19, %21
%23 = load i32, i32* %8
%24 = shl i32 %23, 48
%25 = or i32 %22, %24
store i32 %25, i32* %14
%26 = load i32*, i32** %11
%27 = call i32 @fwrite(i32* %13, i32 4, i32 1, i32* %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %5
store i32 -1, i32* %6
br label %41
30: ; preds = %5
%31 = load i32*, i32** %11
%32 = call i32 @fwrite(i32* %14, i32 4, i32 1, i32* %31)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %6
br label %41
35: ; preds = %30
%36 = load i32*, i32** %11
%37 = call i32 @fwrite(i32* %15, i32 4, i32 1, i32* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 -1, i32* %6
br label %41
40: ; preds = %35
store i32 0, i32* %6
br label %41
41: ; preds = %40, %39, %34, %29
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
define i32 @tga_header24(i32 %0, i32 %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %6 to i8*
store i32 131072, i32* %6
%10 = bitcast i32* %7 to i8*
%11 = bitcast i32* %8 to i8*
store i32 24, i32* %8
%12 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32* %4)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %21
14: ; preds = %5
%15 = call i32 @fwrite(i32* %7, i32 4, i32 1, i32* %4)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %4)
%19 = icmp ne i32 %18, 1
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %17, %14, %5
%22 = phi i32 [ -1, %5 ], [ -1, %14 ], [ %20, %17 ]
ret i32 %22
}