#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 */
struct djvu {
  int dummy;
};

/* Variables and functions */
int get16(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
void dv_read_iw44(struct djvu *doc, unsigned char *data, int size) {
  printf("BG44 {\n");
  int serial, slices;
  serial = data[0];
  slices = data[1];
  printf("serial = %d\n", serial);
  printf("slices = %d\n", slices);
  if (serial == 0) {
    int comps = data[2] >> 7;
    int version = get16(data + 2) & 0x7fff;
    int width = get16(data + 4);
    int height = get16(data + 6);
    int crdelay = data[8];
    printf("comps = %d\n", comps);
    printf("version = 0x%04x\n", version);
    printf("width = %d\n", width);
    printf("height = %d\n", height);
    printf("crdelay = %d\n", crdelay);
  }
  printf("}\n");
}


x86 assembly (clang, -O0):
<dv_read_iw44>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1225 <dv_read_iw44+0x105>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
sar    $0x7,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1040 <get16@plt>
and    $0x7fff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1040 <get16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
call   1040 <get16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x8(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dv_read_iw44>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
movzbl (%rbx),%ebp
movzbl 0x1(%rbx),%r14d
lea    0xeaa(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jne    1201 <dv_read_iw44+0xd1>
lea    0x2(%rbx),%rdi
movzbl 0x2(%rbx),%ebp
shr    $0x7,%ebp
call   1050 <get16@plt>
mov    %eax,%r14d
and    $0x7fff,%r14d
lea    0x4(%rbx),%rdi
call   1050 <get16@plt>
mov    %eax,%r15d
lea    0x6(%rbx),%rdi
call   1050 <get16@plt>
mov    %eax,%r12d
movzbl 0x8(%rbx),%ebx
lea    0xe65(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe62(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.djvu = type { i32 }
@.str = [8 x i8] c"BG44 {\0A\00"
@.str.1 = [13 x i8] c"serial = %d\0A\00"
@.str.2 = [13 x i8] c"slices = %d\0A\00"
@.str.3 = [12 x i8] c"comps = %d\0A\00"
@.str.4 = [18 x i8] c"version = 0x%04x\0A\00"
@.str.5 = [12 x i8] c"width = %d\0A\00"
@.str.6 = [13 x i8] c"height = %d\0A\00"
@.str.7 = [14 x i8] c"crdelay = %d\0A\00"
@.str.8 = [3 x i8] c"}\0A\00"
define void @dv_read_iw44(%struct.djvu* %0, i8* %1, i32 %2) {
%4 = alloca %struct.djvu*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.djvu* %0, %struct.djvu** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
store i32 %18, i32* %7
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
store i32 %22, i32* %8
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %59
29: ; preds = %3
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, 7
store i32 %34, i32* %9
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = call i32 @get16(i8* %36)
%38 = and i32 %37, 32767
store i32 %38, i32* %10
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = call i32 @get16(i8* %40)
store i32 %41, i32* %11
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 6
%44 = call i32 @get16(i8* %43)
store i32 %44, i32* %12
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 8
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
store i32 %48, i32* %13
%49 = load i32, i32* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %10
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %11
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %12
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %13
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %29, %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.djvu = type { i32 }
@.str.1 = [13 x i8] c"serial = %d\0A\00"
@.str.2 = [13 x i8] c"slices = %d\0A\00"
@.str.3 = [12 x i8] c"comps = %d\0A\00"
@.str.4 = [18 x i8] c"version = 0x%04x\0A\00"
@.str.5 = [12 x i8] c"width = %d\0A\00"
@.str.6 = [13 x i8] c"height = %d\0A\00"
@.str.7 = [14 x i8] c"crdelay = %d\0A\00"
@str = [7 x i8] c"BG44 {\00"
@str.9 = [2 x i8] c"}\00"
define void @dv_read_iw44(%struct.djvu* nocapture readnone %0, i8* %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%5 = load i8, i8* %1
%6 = zext i8 %5 to i32
%7 = getelementptr inbounds i8, i8* %1, i64 1
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%12 = icmp eq i8 %5, 0
br i1 %12, label %13, label %32
13: ; preds = %3
%14 = getelementptr inbounds i8, i8* %1, i64 2
%15 = load i8, i8* %14
%16 = lshr i8 %15, 7
%17 = zext i8 %16 to i32
%18 = tail call i32 @get16(i8* %14)
%19 = and i32 %18, 32767
%20 = getelementptr inbounds i8, i8* %1, i64 4
%21 = tail call i32 @get16(i8* %20)
%22 = getelementptr inbounds i8, i8* %1, i64 6
%23 = tail call i32 @get16(i8* %22)
%24 = getelementptr inbounds i8, i8* %1, i64 8
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %26)
br label %32
32: ; preds = %13, %3
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
ret void
}