#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*/ assert(int);
int /*<<< orphan*/ read_bytes(int /*<<< orphan*/ *, unsigned char *, int);
void read_tga_header(FILE *file, int *width, int *height, int *channels,
                     int *is_rle, int *flip_h, int *flip_v) {
  unsigned char header[18];
  int depth, idlength, imgtype, imgdesc;
  read_bytes(file, header, 18);
  *width = header[12] | (header[13] << 8);
  *height = header[14] | (header[15] << 8);
  assert(*width > 0 && *height > 0);
  depth = header[16];
  assert(depth == 8 || depth == 24 || depth == 32);
  *channels = depth / 8;
  idlength = header[0];
  assert(idlength == 0);
  ((void)(idlength));
  imgtype = header[2];
  assert(imgtype == 2 || imgtype == 3 || imgtype == 10 || imgtype == 11);
  *is_rle = imgtype == 10 || imgtype == 11;
  imgdesc = header[17];
  *flip_h = imgdesc & 0x10;
  *flip_v = imgdesc & 0x20;
}


x86 assembly (clang, -O0):
<read_tga_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x12,%edx
call   1030 <read_bytes@plt>
movzbl -0x44(%rbp),%ecx
movzbl -0x43(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x42(%rbp),%ecx
movzbl -0x41(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,(%rcx)
mov    %al,-0x61(%rbp)
jle    119b <read_tga_header+0x7b>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
setg   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movzbl -0x40(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    $0x1,%al
cmpl   $0x8,-0x54(%rbp)
mov    %al,-0x62(%rbp)
je     11d7 <read_tga_header+0xb7>
mov    $0x1,%al
cmpl   $0x18,-0x54(%rbp)
mov    %al,-0x62(%rbp)
je     11d7 <read_tga_header+0xb7>
cmpl   $0x20,-0x54(%rbp)
sete   %al
mov    %al,-0x62(%rbp)
mov    -0x62(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x54(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x50(%rbp),%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movzbl -0x4e(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x1,%al
cmpl   $0x2,-0x5c(%rbp)
mov    %al,-0x63(%rbp)
je     124d <read_tga_header+0x12d>
mov    $0x1,%al
cmpl   $0x3,-0x5c(%rbp)
mov    %al,-0x63(%rbp)
je     124d <read_tga_header+0x12d>
mov    $0x1,%al
cmpl   $0xa,-0x5c(%rbp)
mov    %al,-0x63(%rbp)
je     124d <read_tga_header+0x12d>
cmpl   $0xb,-0x5c(%rbp)
sete   %al
mov    %al,-0x63(%rbp)
mov    -0x63(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1,%al
cmpl   $0xa,-0x5c(%rbp)
mov    %al,-0x64(%rbp)
je     1273 <read_tga_header+0x153>
cmpl   $0xb,-0x5c(%rbp)
sete   %al
mov    %al,-0x64(%rbp)
mov    -0x64(%rbp),%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x3f(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%ecx
and    $0x10,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%ecx
and    $0x20,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_tga_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    0x50(%rsp),%rbp
mov    %rsp,%rsi
mov    $0x12,%edx
call   1030 <read_bytes@plt>
movzwl 0xc(%rsp),%eax
mov    %eax,(%rbx)
movzwl 0xe(%rsp),%eax
mov    %eax,0x0(%r13)
cmpl   $0x0,(%rbx)
setg   %cl
test   %eax,%eax
setne  %al
and    %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
movzbl 0x10(%rsp),%ebx
cmp    $0x20,%ebx
sete   %al
mov    %ebx,%ecx
and    $0xef,%cl
cmp    $0x8,%cl
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
shr    $0x3,%ebx
mov    %ebx,(%r12)
xor    %edi,%edi
cmpb   $0x0,(%rsp)
sete   %dil
call   1040 <assert@plt>
mov    0x2(%rsp),%al
mov    %eax,%ecx
and    $0xfe,%cl
xor    %ebx,%ebx
cmp    $0xa,%cl
sete   %bl
and    $0xf6,%al
xor    %edi,%edi
cmp    $0x2,%al
sete   %dil
call   1040 <assert@plt>
mov    %ebx,(%r15)
movzbl 0x11(%rsp),%eax
mov    %eax,%ecx
and    $0x10,%ecx
mov    %ecx,(%r14)
and    $0x20,%eax
mov    %eax,0x0(%rbp)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_tga_header(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca [18 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store i32* %6, i32** %14
%20 = load i32*, i32** %8
%21 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 0
%22 = call i32 @read_bytes(i32* %20, i8* %21, i32 18)
%23 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 12
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 13
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = shl i32 %28, 8
%30 = or i32 %25, %29
%31 = load i32*, i32** %9
store i32 %30, i32* %31
%32 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 14
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 15
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl i32 %37, 8
%39 = or i32 %34, %38
%40 = load i32*, i32** %10
store i32 %39, i32* %40
%41 = load i32*, i32** %9
%42 = load i32, i32* %41
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %7
%45 = load i32*, i32** %10
%46 = load i32, i32* %45
%47 = icmp sgt i32 %46, 0
br label %48
48: ; preds = %44, %7
%49 = phi i1 [ false, %7 ], [ %47, %44 ]
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 16
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
store i32 %54, i32* %16
%55 = load i32, i32* %16
%56 = icmp eq i32 %55, 8
br i1 %56, label %63, label %57
57: ; preds = %48
%58 = load i32, i32* %16
%59 = icmp eq i32 %58, 24
br i1 %59, label %63, label %60
60: ; preds = %57
%61 = load i32, i32* %16
%62 = icmp eq i32 %61, 32
br label %63
63: ; preds = %60, %57, %48
%64 = phi i1 [ true, %57 ], [ true, %48 ], [ %62, %60 ]
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load i32, i32* %16
%68 = sdiv i32 %67, 8
%69 = load i32*, i32** %11
store i32 %68, i32* %69
%70 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 0
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
store i32 %72, i32* %17
%73 = load i32, i32* %17
%74 = icmp eq i32 %73, 0
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = load i32, i32* %17
%78 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 2
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
store i32 %80, i32* %18
%81 = load i32, i32* %18
%82 = icmp eq i32 %81, 2
br i1 %82, label %92, label %83
83: ; preds = %63
%84 = load i32, i32* %18
%85 = icmp eq i32 %84, 3
br i1 %85, label %92, label %86
86: ; preds = %83
%87 = load i32, i32* %18
%88 = icmp eq i32 %87, 10
br i1 %88, label %92, label %89
89: ; preds = %86
%90 = load i32, i32* %18
%91 = icmp eq i32 %90, 11
br label %92
92: ; preds = %89, %86, %83, %63
%93 = phi i1 [ true, %86 ], [ true, %83 ], [ true, %63 ], [ %91, %89 ]
%94 = zext i1 %93 to i32
%95 = call i32 @assert(i32 %94)
%96 = load i32, i32* %18
%97 = icmp eq i32 %96, 10
br i1 %97, label %101, label %98
98: ; preds = %92
%99 = load i32, i32* %18
%100 = icmp eq i32 %99, 11
br label %101
101: ; preds = %98, %92
%102 = phi i1 [ true, %92 ], [ %100, %98 ]
%103 = zext i1 %102 to i32
%104 = load i32*, i32** %12
store i32 %103, i32* %104
%105 = getelementptr inbounds [18 x i8], [18 x i8]* %15, i64 0, i64 17
%106 = load i8, i8* %105
%107 = zext i8 %106 to i32
store i32 %107, i32* %19
%108 = load i32, i32* %19
%109 = and i32 %108, 16
%110 = load i32*, i32** %13
store i32 %109, i32* %110
%111 = load i32, i32* %19
%112 = and i32 %111, 32
%113 = load i32*, i32** %14
store i32 %112, i32* %113
ret void
}

LLVM IR (-O2):
define void @read_tga_header(i32* %0, i32* nocapture %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6) {
%8 = alloca [18 x i8]
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 0
%10 = call i32 @read_bytes(i32* %0, i8* %9, i32 18)
%11 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 12
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = or i32 %17, %13
store i32 %18, i32* %1
%19 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 14
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 15
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 8
%26 = or i32 %25, %21
store i32 %26, i32* %2
%27 = load i32, i32* %1
%28 = icmp sgt i32 %27, 0
%29 = icmp ne i32 %26, 0
%30 = select i1 %28, i1 %29, i1 false
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 16
%34 = load i8, i8* %33
%35 = and i8 %34, -17
%36 = icmp eq i8 %35, 8
%37 = icmp eq i8 %34, 32
%38 = or i1 %37, %36
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = lshr i8 %34, 3
%42 = zext i8 %41 to i32
store i32 %42, i32* %3
%43 = load i8, i8* %9
%44 = icmp eq i8 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 2
%48 = load i8, i8* %47
%49 = and i8 %48, -2
%50 = icmp eq i8 %49, 10
%51 = and i8 %48, -10
%52 = icmp eq i8 %51, 2
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = zext i1 %50 to i32
store i32 %55, i32* %4
%56 = getelementptr inbounds [18 x i8], [18 x i8]* %8, i64 0, i64 17
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = and i32 %58, 16
store i32 %59, i32* %5
%60 = and i32 %58, 32
store i32 %60, i32* %6
ret void
}