#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 get24(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
void dv_read_fgbz(struct djvu *doc, unsigned char *data, int size) {
  int hascorr;
  int colors, i;
  hascorr = data[0] >> 7;
  colors = get16(data + 1);
  printf("palette (%d) {\n", colors);
  for (i = 0; i < colors; i++)
    printf("\t0x%06x\n", get24(data + 3 + i * 3));
  printf("}\n");
  if (hascorr) {
    int datasize;
    unsigned char *sdata = data + 3 + colors * 3;
    datasize = get24(sdata);
    printf("correspondence (%d) {\n", datasize);
    for (i = 0; i < datasize; i++)
      printf("\t0x%06x\n", get24(sdata + 3 + i * 16));
    printf("}\n");
  }
}


x86 assembly (clang, -O0):
<dv_read_fgbz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
sar    $0x7,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <get16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b8 <dv_read_fgbz+0x88>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
imul   $0x3,-0x20(%rbp),%eax
cltq
add    %rax,%rdi
call   1030 <get24@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1178 <dv_read_fgbz+0x48>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     125a <dv_read_fgbz+0x12a>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
imul   $0x3,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <get24@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    124c <dv_read_fgbz+0x11c>
mov    -0x30(%rbp),%rdi
add    $0x3,%rdi
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
call   1030 <get24@plt>
mov    %eax,%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    120a <dv_read_fgbz+0xda>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dv_read_fgbz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rsi),%r13b
lea    0x1(%rsi),%rdi
call   1060 <get16@plt>
mov    %eax,%r15d
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    119e <dv_read_fgbz+0x5e>
lea    0x3(%r14),%rbx
mov    %r15d,%ebp
lea    0xe90(%rip),%r12
mov    %rbx,%rdi
call   1040 <get24@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x3,%rbx
add    $0xffffffffffffffff,%rbp
jne    1180 <dv_read_fgbz+0x40>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
test   %r13b,%r13b
js     11be <dv_read_fgbz+0x7e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    (%r15,%r15,2),%eax
cltq
lea    (%r14,%rax,1),%rbx
add    $0x3,%rbx
mov    %rbx,%rdi
call   1040 <get24@plt>
mov    %eax,%ebp
lea    0xe3c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    121e <dv_read_fgbz+0xde>
add    $0x3,%rbx
mov    %ebp,%ebp
lea    0xe19(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <get24@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x10,%rbx
add    $0xffffffffffffffff,%rbp
jne    1200 <dv_read_fgbz+0xc0>
lea    0xe0b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.djvu = type { i32 }
@.str = [16 x i8] c"palette (%d) {\0A\00"
@.str.1 = [9 x i8] c"\090x%06x\0A\00"
@.str.2 = [3 x i8] c"}\0A\00"
@.str.3 = [23 x i8] c"correspondence (%d) {\0A\00"
define void @dv_read_fgbz(%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 i8*
store %struct.djvu* %0, %struct.djvu** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = ashr i32 %15, 7
store i32 %16, i32* %7
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = call i32 @get16(i8* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 0, i32* %9
br label %22
22: ; preds = %35, %3
%23 = load i32, i32* %9
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = load i32, i32* %9
%30 = mul nsw i32 %29, 3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = call i32 @get24(i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %26
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %22
38: ; preds = %22
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %71
42: ; preds = %38
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 3
%45 = load i32, i32* %8
%46 = mul nsw i32 %45, 3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = call i32 @get24(i8* %49)
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %51)
store i32 0, i32* %9
br label %53
53: ; preds = %66, %42
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %69
57: ; preds = %53
%58 = load i8*, i8** %11
%59 = getelementptr inbounds i8, i8* %58, i64 3
%60 = load i32, i32* %9
%61 = mul nsw i32 %60, 16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = call i32 @get24(i8* %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %57
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %53
69: ; preds = %53
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %71
71: ; preds = %69, %38
ret void
}

LLVM IR (-O2):
%struct.djvu = type { i32 }
@.str = [16 x i8] c"palette (%d) {\0A\00"
@.str.1 = [9 x i8] c"\090x%06x\0A\00"
@.str.3 = [23 x i8] c"correspondence (%d) {\0A\00"
@str.4 = [2 x i8] c"}\00"
define void @dv_read_fgbz(%struct.djvu* nocapture readnone %0, i8* %1, i32 %2) {
%4 = load i8, i8* %1
%5 = getelementptr inbounds i8, i8* %1, i64 1
%6 = tail call i32 @get16(i8* %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %6, 0
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %1, i64 3
%11 = zext i32 %6 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %18, %12 ]
%14 = mul nuw nsw i64 %13, 3
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = tail call i32 @get24(i8* %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12, %3
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%22 = icmp sgt i8 %4, -1
br i1 %22, label %44, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %1, i64 3
%25 = mul nsw i32 %6, 3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = tail call i32 @get24(i8* %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = icmp sgt i32 %28, 0
br i1 %30, label %31, label %42
31: ; preds = %23
%32 = getelementptr inbounds i8, i8* %27, i64 3
%33 = zext i32 %28 to i64
br label %34
34: ; preds = %31, %34
%35 = phi i64 [ 0, %31 ], [ %40, %34 ]
%36 = shl nsw i64 %35, 4
%37 = getelementptr inbounds i8, i8* %32, i64 %36
%38 = tail call i32 @get24(i8* %37)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = add nuw nsw i64 %35, 1
%41 = icmp eq i64 %40, %33
br i1 %41, label %42, label %34
42: ; preds = %34, %23
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %20
ret void
}