#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*/ buildpacket(unsigned char *, int *, int, unsigned char *,
                               int);
int /*<<< orphan*/ convint(unsigned char *, int);
int getint(unsigned char *);
int listen(int, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, unsigned char *, int);
int checkhoffset(int fd, int hoffset) {
  unsigned char pak[1024];
  unsigned char buf[1024];
  int len, res;
  int video;
  unsigned char p[4];
  p[0] = 0x01;
  p[1] = 0x00;
  convint(&p[2], hoffset);
  buildpacket(pak, &len, 0x12, p, 4);
  write(fd, pak, len);
  res = listen(fd, buf);
  if (res > 1)
    video = getint(&buf[4]);
  else {
    printf("No response from CPU to read_blank_video.\n");
    return 0;
  }
  printf("CCD black level:  %d\n", video);
  if (video >= 1000 && video <= 10000)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<checkhoffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x1,-0x820(%rbp)
movb   $0x0,-0x81f(%rbp)
lea    -0x820(%rbp),%rdi
add    $0x2,%rdi
mov    -0xc(%rbp),%esi
call   1080 <convint@plt>
lea    -0x410(%rbp),%rdi
lea    -0x820(%rbp),%rcx
lea    -0x814(%rbp),%rsi
mov    $0x12,%edx
mov    $0x4,%r8d
call   1060 <buildpacket@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1070 <listen@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x1,-0x818(%rbp)
jle    1209 <checkhoffset+0xa9>
lea    -0x810(%rbp),%rdi
add    $0x4,%rdi
call   1050 <getint@plt>
mov    %eax,-0x81c(%rbp)
jmp    1223 <checkhoffset+0xc3>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126a <checkhoffset+0x10a>
mov    -0x81c(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3e8,-0x81c(%rbp)
jl     1263 <checkhoffset+0x103>
cmpl   $0x2710,-0x81c(%rbp)
jg     1263 <checkhoffset+0x103>
movl   $0x1,-0x4(%rbp)
jmp    126a <checkhoffset+0x10a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkhoffset>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %edi,%ebx
movw   $0x1,0x8(%rsp)
lea    0xa(%rsp),%rdi
call   1090 <convint@plt>
lea    0x410(%rsp),%r14
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    $0x12,%edx
mov    $0x4,%r8d
call   1070 <buildpacket@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   1080 <listen@plt>
cmp    $0x2,%eax
jl     1200 <checkhoffset+0x90>
lea    0x14(%rsp),%rdi
call   1060 <getint@plt>
mov    %eax,%ebx
lea    0xe1c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xfffffc18,%ebx
xor    %eax,%eax
cmp    $0x2329,%ebx
setb   %al
jmp    120e <checkhoffset+0x9e>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"No response from CPU to read_blank_video.\0A\00"
@.str.1 = [22 x i8] c"CCD black level: %d\0A\00"
define i32 @checkhoffset(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
store i8 1, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 1
store i8 0, i8* %13
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 2
%15 = load i32, i32* %5
%16 = call i32 @convint(i8* %14, i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%19 = call i32 @buildpacket(i8* %17, i32* %8, i32 18, i8* %18, i32 4)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %8
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %4
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = call i32 @listen(i32 %24, i8* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %2
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 4
%31 = call i32 @getint(i8* %30)
store i32 %31, i32* %10
br label %34
32: ; preds = %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %44
34: ; preds = %29
%35 = load i32, i32* %10
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %10
%38 = icmp sge i32 %37, 1000
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* %10
%41 = icmp sle i32 %40, 10000
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1, i32* %3
br label %44
43: ; preds = %39, %34
store i32 0, i32* %3
br label %44
44: ; preds = %43, %42, %32
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"CCD black level: %d\0A\00"
@str = [42 x i8] c"No response from CPU to read_blank_video.\00"
define i32 @checkhoffset(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 1, i8* %10
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 0, i8* %11
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%13 = call i32 @convint(i8* %12, i32 %1)
%14 = call i32 @buildpacket(i8* %7, i32* %5, i32 18, i8* %10, i32 4)
%15 = load i32, i32* %5
%16 = call i32 @write(i32 %0, i8* %7, i32 %15)
%17 = call i32 @listen(i32 %0, i8* %8)
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 4
%21 = call i32 @getint(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add i32 %21, -1000
%24 = icmp ult i32 %23, 9001
%25 = zext i1 %24 to i32
br label %28
26: ; preds = %2
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %19, %26
%29 = phi i32 [ 0, %26 ], [ %25, %19 ]
ret i32 %29
}