#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 */

/* Variables and functions */
int /*<<< orphan*/ free(struct CalBlock *);
int /*<<< orphan*/ hp5400_bulk_command_write(int, int, char *, int, int, int,
                                             void *);
struct CalBlock *malloc(int);
int /*<<< orphan*/ memset(struct CalBlock *, int /*<<< orphan*/, int);
int SetCalibration(int iHandle, int numPixels, unsigned int *low_vals[3],
                   unsigned int *high_vals[3], int dpi) {
  char cmd[8];
  int i, j, k;
  struct CalPixel {
    char highr[2], highg[2], highb[2];
    char lowr[2], lowg[2], lowb[2];
  };
  struct CalBlock {
    struct CalPixel pixels[42];
    char pad[8];
  } __attribute__((packed));
  struct CalBlock *calinfo;
  int numLoop = (((1) > (dpi / 300)) ? (1) : (dpi / 300));
  int calBlockSize = 42 * (6 * sizeof(short)) + 8 * sizeof(char);
  int numCalBlock = ((numPixels / 42) + ((numPixels % 42 != 0) ? 1 : 0));
  int calSize = numLoop * calBlockSize * numCalBlock;
  calinfo = malloc(calSize);
  memset(calinfo, 0, calSize);
  for (j = 0; j < numLoop * numCalBlock * 42; j++) {
    struct CalPixel *pixel = &calinfo[j / 42].pixels[j % 42];
    i = j / numLoop;
    k = (high_vals[0][i] > 0x4000) ? 1000000000 / high_vals[0][i] : 0;
    pixel->highr[0] = k;
    pixel->highr[1] = k >> 8;
    k = (high_vals[1][i] > 0x4000) ? 1000000000 / high_vals[1][i] : 0;
    pixel->highg[0] = k;
    pixel->highg[1] = k >> 8;
    k = (high_vals[2][i] > 0x4000) ? 1000000000 / high_vals[2][i] : 0;
    pixel->highb[0] = k;
    pixel->highb[1] = k >> 8;
    pixel->lowr[0] = low_vals[0][i];
    pixel->lowr[1] = low_vals[0][i] >> 8;
    pixel->lowg[0] = low_vals[1][i];
    pixel->lowg[1] = low_vals[1][i] >> 8;
    pixel->lowb[0] = low_vals[2][i];
    pixel->lowb[1] = low_vals[2][i] >> 8;
  }
  cmd[0] = 0xff & (calSize >> 16);
  cmd[1] = 0xff & (calSize >> 8);
  cmd[2] = 0xff & (calSize >> 0);
  cmd[3] = 0x00;
  cmd[4] = 0x54;
  cmd[5] = 0x02;
  cmd[6] = 0x80;
  cmd[7] = 0x00;
  hp5400_bulk_command_write(iHandle, 0xE603, cmd, 8, calSize, calSize,
                            (void *)calinfo);
  free(calinfo);
  return 0;
}


x86 assembly (clang, -O0):
<SetCalibration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x12c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jle    1184 <SetCalibration+0x44>
mov    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1192 <SetCalibration+0x52>
mov    -0x1c(%rbp),%eax
mov    $0x12c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x200,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2a,%ecx
cltd
idiv   %ecx
mov    -0x58(%rbp),%eax
mov    %edx,%esi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x3c(%rbp),%eax
imul   -0x40(%rbp),%eax
imul   -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x3c(%rbp),%ecx
imul   -0x44(%rbp),%ecx
imul   $0x2a,%ecx,%ecx
cmp    %ecx,%eax
jge    1429 <SetCalibration+0x2e9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2a,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
shl    $0x9,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2a,%ecx
cltd
idiv   %ecx
mov    -0x60(%rbp),%rax
movslq %edx,%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x3c(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x4000,(%rax,%rcx,4)
jbe    1296 <SetCalibration+0x156>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq -0x28(%rbp),%rsi
mov    $0x3b9aca00,%eax
xor    %edx,%edx
divl   (%rcx,%rsi,4)
mov    %eax,-0x6c(%rbp)
jmp    12a0 <SetCalibration+0x160>
xor    %eax,%eax
mov    %eax,-0x6c(%rbp)
jmp    12a0 <SetCalibration+0x160>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x4000,(%rax,%rcx,4)
jbe    12f7 <SetCalibration+0x1b7>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
movslq -0x28(%rbp),%rsi
mov    $0x3b9aca00,%eax
xor    %edx,%edx
divl   (%rcx,%rsi,4)
mov    %eax,-0x70(%rbp)
jmp    1301 <SetCalibration+0x1c1>
xor    %eax,%eax
mov    %eax,-0x70(%rbp)
jmp    1301 <SetCalibration+0x1c1>
mov    -0x70(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x30(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x28(%rbp),%rcx
cmpl   $0x4000,(%rax,%rcx,4)
jbe    1359 <SetCalibration+0x219>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
movslq -0x28(%rbp),%rsi
mov    $0x3b9aca00,%eax
xor    %edx,%edx
divl   (%rcx,%rsi,4)
mov    %eax,-0x74(%rbp)
jmp    1363 <SetCalibration+0x223>
xor    %eax,%eax
mov    %eax,-0x74(%rbp)
jmp    1363 <SetCalibration+0x223>
mov    -0x74(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x30(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0xa(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0xb(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fe <SetCalibration+0xbe>
mov    -0x48(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x24(%rbp)
mov    -0x48(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x23(%rbp)
mov    -0x48(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
movb   $0x54,-0x20(%rbp)
movb   $0x2,-0x1f(%rbp)
movb   $0x80,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rdx
mov    -0x48(%rbp),%r8d
mov    -0x48(%rbp),%r9d
mov    -0x38(%rbp),%rax
mov    $0xe603,%esi
mov    $0x8,%ecx
mov    %rax,(%rsp)
call   1040 <hp5400_bulk_command_write@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetCalibration>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r13
mov    %rdx,%r12
mov    %edi,0x1c(%rsp)
mov    $0x1,%ebx
cmp    $0x12c,%r8d
jl     117d <SetCalibration+0x3d>
movslq %r8d,%rax
imul   $0x1b4e81b5,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x25,%rbx
add    %eax,%ebx
movslq %esi,%rax
imul   $0x30c30c31,%rax,%rbp
mov    %rbp,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rbp
add    %ecx,%ebp
imul   $0x3cf3cf3d,%eax,%eax
add    $0x6186186,%eax
ror    %eax
cmp    $0x6186187,%eax
sbb    $0xffffffff,%ebp
imul   %ebx,%ebp
mov    %ebp,%r14d
shl    $0x9,%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,0x18(%rsp)
mov    %r14d,%edx
call   1050 <memset@plt>
imul   $0x2a,%ebp,%r11d
test   %r11d,%r11d
jle    12fd <SetCalibration+0x1bd>
mov    0x0(%r13),%rax
mov    %rax,0x30(%rsp)
mov    0x8(%r13),%rax
mov    %rax,0x28(%rsp)
mov    0x10(%r13),%r10
mov    (%r12),%r13
mov    0x8(%r12),%r8
mov    0x10(%r12),%rbp
xor    %ecx,%ecx
mov    0x20(%rsp),%r15
jmp    126b <SetCalibration+0x12b>
nopl   0x0(%rax)
mov    %di,0x4(%r15,%rsi,8)
movzbl 0x0(%r13,%r12,4),%eax
mov    %al,0x6(%r15,%rsi,8)
movzbl 0x1(%r13,%r12,4),%eax
mov    %al,0x7(%r15,%rsi,8)
movzbl (%r8,%r12,4),%eax
mov    %al,0x8(%r15,%rsi,8)
movzbl 0x1(%r8,%r12,4),%eax
mov    %al,0x9(%r15,%rsi,8)
movzbl 0x0(%rbp,%r12,4),%eax
mov    %al,0xa(%r15,%rsi,8)
movzbl 0x1(%rbp,%r12,4),%eax
mov    %al,0xb(%r15,%rsi,8)
add    $0x1,%rcx
add    $0xc,%r15
cmp    %ecx,%r11d
mov    %r9,%rbx
je     12fd <SetCalibration+0x1bd>
mov    %rcx,%rax
shr    %rax
movabs $0xc30c30c30c30c30d,%rdx
30 0c c3
mul    %rdx
mov    %rdx,%rsi
shr    $0x4,%rsi
mov    %ecx,%eax
cltd
mov    %rbx,%r9
idiv   %ebx
movslq %eax,%r12
mov    0x30(%rsp),%rax
mov    (%rax,%r12,4),%edi
mov    $0x0,%eax
cmp    $0x4001,%edi
jb     12af <SetCalibration+0x16f>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
div    %edi
mov    %ax,(%r15,%rsi,8)
mov    0x28(%rsp),%rax
mov    (%rax,%r12,4),%r14d
xor    %edi,%edi
mov    $0x0,%eax
cmp    $0x4001,%r14d
jb     12d7 <SetCalibration+0x197>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
div    %r14d
mov    %ax,0x2(%r15,%rsi,8)
mov    (%r10,%r12,4),%ebx
cmp    $0x4001,%ebx
jb     1210 <SetCalibration+0xd0>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%edi
jmp    1210 <SetCalibration+0xd0>
mov    0x18(%rsp),%ecx
mov    %ecx,%eax
shr    $0x10,%eax
mov    %al,0x10(%rsp)
mov    %ch,0x11(%rsp)
movl   $0x2540000,0x12(%rsp)
02
movw   $0x80,0x16(%rsp)
mov    0x20(%rsp),%rbx
mov    %rbx,(%rsp)
lea    0x10(%rsp),%rdx
mov    0x1c(%rsp),%edi
mov    $0xe603,%esi
mov    %ecx,%r8d
mov    %ecx,%r9d
mov    $0x8,%ecx
call   1040 <hp5400_bulk_command_write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.CalBlock = type { [42 x %struct.CalPixel], [8 x i8] }
%struct.CalPixel = type { [2 x i8], [2 x i8], [2 x i8], [2 x i8], [2 x i8], [2 x i8] }
%struct.CalBlock.0 = type opaque
%struct.CalBlock.1 = type opaque
define i32 @SetCalibration(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 [8 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.CalBlock*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca %struct.CalPixel*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32** %2, i32*** %8
store i32** %3, i32*** %9
store i32 %4, i32* %10
%21 = load i32, i32* %10
%22 = sdiv i32 %21, 300
%23 = icmp sgt i32 1, %22
br i1 %23, label %24, label %25
24: ; preds = %5
br label %28
25: ; preds = %5
%26 = load i32, i32* %10
%27 = sdiv i32 %26, 300
br label %28
28: ; preds = %25, %24
%29 = phi i32 [ 1, %24 ], [ %27, %25 ]
store i32 %29, i32* %16
store i32 512, i32* %17
%30 = load i32, i32* %7
%31 = sdiv i32 %30, 42
%32 = load i32, i32* %7
%33 = srem i32 %32, 42
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 1, i32 0
%37 = add nsw i32 %31, %36
store i32 %37, i32* %18
%38 = load i32, i32* %16
%39 = load i32, i32* %17
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %18
%42 = mul nsw i32 %40, %41
store i32 %42, i32* %19
%43 = load i32, i32* %19
%44 = call %struct.CalBlock.0* @malloc(i32 %43)
%45 = bitcast %struct.CalBlock.0* %44 to %struct.CalBlock*
store %struct.CalBlock* %45, %struct.CalBlock** %15
%46 = load %struct.CalBlock*, %struct.CalBlock** %15
%47 = bitcast %struct.CalBlock* %46 to %struct.CalBlock.0*
%48 = load i32, i32* %19
%49 = call i32 @memset(%struct.CalBlock.0* %47, i32 0, i32 %48)
store i32 0, i32* %13
br label %50
50: ; preds = %233, %28
%51 = load i32, i32* %13
%52 = load i32, i32* %16
%53 = load i32, i32* %18
%54 = mul nsw i32 %52, %53
%55 = mul nsw i32 %54, 42
%56 = icmp slt i32 %51, %55
br i1 %56, label %57, label %236
57: ; preds = %50
%58 = load %struct.CalBlock*, %struct.CalBlock** %15
%59 = load i32, i32* %13
%60 = sdiv i32 %59, 42
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %58, i64 %61
%63 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %62, i32 0, i32 0
%64 = load i32, i32* %13
%65 = srem i32 %64, 42
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [42 x %struct.CalPixel], [42 x %struct.CalPixel]* %63, i64 0, i64 %66
store %struct.CalPixel* %67, %struct.CalPixel** %20
%68 = load i32, i32* %13
%69 = load i32, i32* %16
%70 = sdiv i32 %68, %69
store i32 %70, i32* %12
%71 = load i32**, i32*** %9
%72 = getelementptr inbounds i32*, i32** %71, i64 0
%73 = load i32*, i32** %72
%74 = load i32, i32* %12
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
%77 = load i32, i32* %76
%78 = icmp ugt i32 %77, 16384
br i1 %78, label %79, label %88
79: ; preds = %57
%80 = load i32**, i32*** %9
%81 = getelementptr inbounds i32*, i32** %80, i64 0
%82 = load i32*, i32** %81
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = udiv i32 1000000000, %86
br label %89
88: ; preds = %57
br label %89
89: ; preds = %88, %79
%90 = phi i32 [ %87, %79 ], [ 0, %88 ]
store i32 %90, i32* %14
%91 = load i32, i32* %14
%92 = trunc i32 %91 to i8
%93 = load %struct.CalPixel*, %struct.CalPixel** %20
%94 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %93, i32 0, i32 0
%95 = getelementptr inbounds [2 x i8], [2 x i8]* %94, i64 0, i64 0
store i8 %92, i8* %95
%96 = load i32, i32* %14
%97 = ashr i32 %96, 8
%98 = trunc i32 %97 to i8
%99 = load %struct.CalPixel*, %struct.CalPixel** %20
%100 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %99, i32 0, i32 0
%101 = getelementptr inbounds [2 x i8], [2 x i8]* %100, i64 0, i64 1
store i8 %98, i8* %101
%102 = load i32**, i32*** %9
%103 = getelementptr inbounds i32*, i32** %102, i64 1
%104 = load i32*, i32** %103
%105 = load i32, i32* %12
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %104, i64 %106
%108 = load i32, i32* %107
%109 = icmp ugt i32 %108, 16384
br i1 %109, label %110, label %119
110: ; preds = %89
%111 = load i32**, i32*** %9
%112 = getelementptr inbounds i32*, i32** %111, i64 1
%113 = load i32*, i32** %112
%114 = load i32, i32* %12
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i32, i32* %113, i64 %115
%117 = load i32, i32* %116
%118 = udiv i32 1000000000, %117
br label %120
119: ; preds = %89
br label %120
120: ; preds = %119, %110
%121 = phi i32 [ %118, %110 ], [ 0, %119 ]
store i32 %121, i32* %14
%122 = load i32, i32* %14
%123 = trunc i32 %122 to i8
%124 = load %struct.CalPixel*, %struct.CalPixel** %20
%125 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %124, i32 0, i32 1
%126 = getelementptr inbounds [2 x i8], [2 x i8]* %125, i64 0, i64 0
store i8 %123, i8* %126
%127 = load i32, i32* %14
%128 = ashr i32 %127, 8
%129 = trunc i32 %128 to i8
%130 = load %struct.CalPixel*, %struct.CalPixel** %20
%131 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %130, i32 0, i32 1
%132 = getelementptr inbounds [2 x i8], [2 x i8]* %131, i64 0, i64 1
store i8 %129, i8* %132
%133 = load i32**, i32*** %9
%134 = getelementptr inbounds i32*, i32** %133, i64 2
%135 = load i32*, i32** %134
%136 = load i32, i32* %12
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i32, i32* %135, i64 %137
%139 = load i32, i32* %138
%140 = icmp ugt i32 %139, 16384
br i1 %140, label %141, label %150
141: ; preds = %120
%142 = load i32**, i32*** %9
%143 = getelementptr inbounds i32*, i32** %142, i64 2
%144 = load i32*, i32** %143
%145 = load i32, i32* %12
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i32, i32* %144, i64 %146
%148 = load i32, i32* %147
%149 = udiv i32 1000000000, %148
br label %151
150: ; preds = %120
br label %151
151: ; preds = %150, %141
%152 = phi i32 [ %149, %141 ], [ 0, %150 ]
store i32 %152, i32* %14
%153 = load i32, i32* %14
%154 = trunc i32 %153 to i8
%155 = load %struct.CalPixel*, %struct.CalPixel** %20
%156 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %155, i32 0, i32 2
%157 = getelementptr inbounds [2 x i8], [2 x i8]* %156, i64 0, i64 0
store i8 %154, i8* %157
%158 = load i32, i32* %14
%159 = ashr i32 %158, 8
%160 = trunc i32 %159 to i8
%161 = load %struct.CalPixel*, %struct.CalPixel** %20
%162 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %161, i32 0, i32 2
%163 = getelementptr inbounds [2 x i8], [2 x i8]* %162, i64 0, i64 1
store i8 %160, i8* %163
%164 = load i32**, i32*** %8
%165 = getelementptr inbounds i32*, i32** %164, i64 0
%166 = load i32*, i32** %165
%167 = load i32, i32* %12
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i32, i32* %166, i64 %168
%170 = load i32, i32* %169
%171 = trunc i32 %170 to i8
%172 = load %struct.CalPixel*, %struct.CalPixel** %20
%173 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %172, i32 0, i32 3
%174 = getelementptr inbounds [2 x i8], [2 x i8]* %173, i64 0, i64 0
store i8 %171, i8* %174
%175 = load i32**, i32*** %8
%176 = getelementptr inbounds i32*, i32** %175, i64 0
%177 = load i32*, i32** %176
%178 = load i32, i32* %12
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32, i32* %177, i64 %179
%181 = load i32, i32* %180
%182 = lshr i32 %181, 8
%183 = trunc i32 %182 to i8
%184 = load %struct.CalPixel*, %struct.CalPixel** %20
%185 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %184, i32 0, i32 3
%186 = getelementptr inbounds [2 x i8], [2 x i8]* %185, i64 0, i64 1
store i8 %183, i8* %186
%187 = load i32**, i32*** %8
%188 = getelementptr inbounds i32*, i32** %187, i64 1
%189 = load i32*, i32** %188
%190 = load i32, i32* %12
%191 = sext i32 %190 to i64
%192 = getelementptr inbounds i32, i32* %189, i64 %191
%193 = load i32, i32* %192
%194 = trunc i32 %193 to i8
%195 = load %struct.CalPixel*, %struct.CalPixel** %20
%196 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %195, i32 0, i32 4
%197 = getelementptr inbounds [2 x i8], [2 x i8]* %196, i64 0, i64 0
store i8 %194, i8* %197
%198 = load i32**, i32*** %8
%199 = getelementptr inbounds i32*, i32** %198, i64 1
%200 = load i32*, i32** %199
%201 = load i32, i32* %12
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i32, i32* %200, i64 %202
%204 = load i32, i32* %203
%205 = lshr i32 %204, 8
%206 = trunc i32 %205 to i8
%207 = load %struct.CalPixel*, %struct.CalPixel** %20
%208 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %207, i32 0, i32 4
%209 = getelementptr inbounds [2 x i8], [2 x i8]* %208, i64 0, i64 1
store i8 %206, i8* %209
%210 = load i32**, i32*** %8
%211 = getelementptr inbounds i32*, i32** %210, i64 2
%212 = load i32*, i32** %211
%213 = load i32, i32* %12
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds i32, i32* %212, i64 %214
%216 = load i32, i32* %215
%217 = trunc i32 %216 to i8
%218 = load %struct.CalPixel*, %struct.CalPixel** %20
%219 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %218, i32 0, i32 5
%220 = getelementptr inbounds [2 x i8], [2 x i8]* %219, i64 0, i64 0
store i8 %217, i8* %220
%221 = load i32**, i32*** %8
%222 = getelementptr inbounds i32*, i32** %221, i64 2
%223 = load i32*, i32** %222
%224 = load i32, i32* %12
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds i32, i32* %223, i64 %225
%227 = load i32, i32* %226
%228 = lshr i32 %227, 8
%229 = trunc i32 %228 to i8
%230 = load %struct.CalPixel*, %struct.CalPixel** %20
%231 = getelementptr inbounds %struct.CalPixel, %struct.CalPixel* %230, i32 0, i32 5
%232 = getelementptr inbounds [2 x i8], [2 x i8]* %231, i64 0, i64 1
store i8 %229, i8* %232
br label %233
233: ; preds = %151
%234 = load i32, i32* %13
%235 = add nsw i32 %234, 1
store i32 %235, i32* %13
br label %50
236: ; preds = %50
%237 = load i32, i32* %19
%238 = ashr i32 %237, 16
%239 = and i32 255, %238
%240 = trunc i32 %239 to i8
%241 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
store i8 %240, i8* %241
%242 = load i32, i32* %19
%243 = ashr i32 %242, 8
%244 = and i32 255, %243
%245 = trunc i32 %244 to i8
%246 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 1
store i8 %245, i8* %246
%247 = load i32, i32* %19
%248 = ashr i32 %247, 0
%249 = and i32 255, %248
%250 = trunc i32 %249 to i8
%251 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 2
store i8 %250, i8* %251
%252 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 3
store i8 0, i8* %252
%253 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 4
store i8 84, i8* %253
%254 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 5
store i8 2, i8* %254
%255 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 6
store i8 -128, i8* %255
%256 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 7
store i8 0, i8* %256
%257 = load i32, i32* %6
%258 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%259 = load i32, i32* %19
%260 = load i32, i32* %19
%261 = load %struct.CalBlock*, %struct.CalBlock** %15
%262 = bitcast %struct.CalBlock* %261 to i8*
%263 = call i32 @hp5400_bulk_command_write(i32 %257, i32 58883, i8* %258, i32 8, i32 %259, i32 %260, i8* %262)
%264 = load %struct.CalBlock*, %struct.CalBlock** %15
%265 = bitcast %struct.CalBlock* %264 to %struct.CalBlock.1*
%266 = call i32 @free(%struct.CalBlock.1* %265)
ret i32 0
}

LLVM IR (-O2):
%struct.CalBlock.0 = type opaque
%struct.CalBlock = type { [42 x %struct.CalPixel], [8 x i8] }
%struct.CalPixel = type { [2 x i8], [2 x i8], [2 x i8], [2 x i8], [2 x i8], [2 x i8] }
%struct.CalBlock.1 = type opaque
define i32 @SetCalibration(i32 %0, i32 %1, i32** nocapture %2, i32** nocapture %3, i32 %4) {
%6 = alloca [8 x i8]
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%8 = icmp slt i32 %4, 300
%9 = sdiv i32 %4, 300
%10 = select i1 %8, i32 1, i32 %9
%11 = sdiv i32 %1, 42
%12 = srem i32 %1, 42
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add nsw i32 %11, %14
%16 = shl nsw i32 %10, 9
%17 = mul nsw i32 %16, %15
%18 = tail call %struct.CalBlock.0* @malloc(i32 %17)
%19 = bitcast %struct.CalBlock.0* %18 to %struct.CalBlock*
%20 = tail call i32 @memset(%struct.CalBlock.0* %18, i32 0, i32 %17)
%21 = mul i32 %15, 42
%22 = mul i32 %21, %10
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %105
24: ; preds = %5
%25 = load i32*, i32** %3
%26 = getelementptr inbounds i32*, i32** %3, i64 1
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32*, i32** %3, i64 2
%29 = load i32*, i32** %28
%30 = load i32*, i32** %2
%31 = getelementptr inbounds i32*, i32** %2, i64 1
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32*, i32** %2, i64 2
%34 = load i32*, i32** %33
br label %35
35: ; preds = %24, %72
%36 = phi i32 [ 0, %24 ], [ %103, %72 ]
%37 = udiv i32 %36, 42
%38 = zext i32 %37 to i64
%39 = urem i32 %36, 42
%40 = zext i32 %39 to i64
%41 = sdiv i32 %36, %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %25, i64 %42
%44 = load i32, i32* %43
%45 = icmp ugt i32 %44, 16384
br i1 %45, label %46, label %48
46: ; preds = %35
%47 = udiv i32 1000000000, %44
br label %48
48: ; preds = %35, %46
%49 = phi i32 [ %47, %46 ], [ 0, %35 ]
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 0, i64 0
store i8 %50, i8* %51
%52 = lshr i32 %49, 8
%53 = trunc i32 %52 to i8
%54 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 0, i64 1
store i8 %53, i8* %54
%55 = getelementptr inbounds i32, i32* %27, i64 %42
%56 = load i32, i32* %55
%57 = icmp ugt i32 %56, 16384
br i1 %57, label %58, label %60
58: ; preds = %48
%59 = udiv i32 1000000000, %56
br label %60
60: ; preds = %48, %58
%61 = phi i32 [ %59, %58 ], [ 0, %48 ]
%62 = trunc i32 %61 to i8
%63 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 1, i64 0
store i8 %62, i8* %63
%64 = lshr i32 %61, 8
%65 = trunc i32 %64 to i8
%66 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 1, i64 1
store i8 %65, i8* %66
%67 = getelementptr inbounds i32, i32* %29, i64 %42
%68 = load i32, i32* %67
%69 = icmp ugt i32 %68, 16384
br i1 %69, label %70, label %72
70: ; preds = %60
%71 = udiv i32 1000000000, %68
br label %72
72: ; preds = %60, %70
%73 = phi i32 [ %71, %70 ], [ 0, %60 ]
%74 = trunc i32 %73 to i8
%75 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 2, i64 0
store i8 %74, i8* %75
%76 = lshr i32 %73, 8
%77 = trunc i32 %76 to i8
%78 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 2, i64 1
store i8 %77, i8* %78
%79 = getelementptr inbounds i32, i32* %30, i64 %42
%80 = load i32, i32* %79
%81 = trunc i32 %80 to i8
%82 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 3, i64 0
store i8 %81, i8* %82
%83 = load i32, i32* %79
%84 = lshr i32 %83, 8
%85 = trunc i32 %84 to i8
%86 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 3, i64 1
store i8 %85, i8* %86
%87 = getelementptr inbounds i32, i32* %32, i64 %42
%88 = load i32, i32* %87
%89 = trunc i32 %88 to i8
%90 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 4, i64 0
store i8 %89, i8* %90
%91 = load i32, i32* %87
%92 = lshr i32 %91, 8
%93 = trunc i32 %92 to i8
%94 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 4, i64 1
store i8 %93, i8* %94
%95 = getelementptr inbounds i32, i32* %34, i64 %42
%96 = load i32, i32* %95
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 5, i64 0
store i8 %97, i8* %98
%99 = load i32, i32* %95
%100 = lshr i32 %99, 8
%101 = trunc i32 %100 to i8
%102 = getelementptr inbounds %struct.CalBlock, %struct.CalBlock* %19, i64 %38, i32 0, i64 %40, i32 5, i64 1
store i8 %101, i8* %102
%103 = add nuw nsw i32 %36, 1
%104 = icmp eq i32 %103, %22
br i1 %104, label %105, label %35
105: ; preds = %72, %5
%106 = lshr i32 %17, 16
%107 = trunc i32 %106 to i8
store i8 %107, i8* %7
%108 = lshr exact i32 %17, 8
%109 = trunc i32 %108 to i8
%110 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
store i8 %109, i8* %110
%111 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
store i8 0, i8* %111
%112 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 3
store i8 0, i8* %112
%113 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
store i8 84, i8* %113
%114 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
store i8 2, i8* %114
%115 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 6
store i8 -128, i8* %115
%116 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 7
store i8 0, i8* %116
%117 = bitcast %struct.CalBlock.0* %18 to i8*
%118 = call i32 @hp5400_bulk_command_write(i32 %0, i32 58883, i8* %7, i32 8, i32 %17, i32 %17, i8* %117)
%119 = bitcast %struct.CalBlock.0* %18 to %struct.CalBlock.1*
%120 = call i32 @free(%struct.CalBlock.1* %119)
ret i32 0
}