#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 timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ buildpacket(unsigned char *, int *, int, unsigned char *,
                               int);
int checkidle(int);
int /*<<< orphan*/ convint(unsigned char *, int);
int listen(int, unsigned char *);
int /*<<< orphan*/ nanosleep(struct timespec, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int takedarkimage(int fd) {
  unsigned char pak[1024];
  unsigned char buf[1024];
  int len, res;
  int DONE = 0;
  unsigned char p[28];
  convint(&p[0], 200);
  convint(&p[2], 0);
  convint(&p[4], 0);
  convint(&p[6], 121);
  convint(&p[8], 0);
  convint(&p[10], 250);
  convint(&p[12], 0);
  convint(&p[14], 0);
  convint(&p[16], 0);
  convint(&p[18], 6000);
  convint(&p[20], 0);
  convint(&p[22], 0);
  convint(&p[24], 3);
  convint(&p[26], 0);
  buildpacket(pak, &len, 0x01, p, 28);
  write(fd, pak, len);
  res = listen(fd, buf);
  if (!(res == 1 && buf[0] == 0x06)) {
    printf("Problem taking image.\n");
    return 0;
  } else
    printf("Taking image ...\n");
  struct timespec wait;
  wait.tv_sec = 0;
  wait.tv_nsec = 370000000;
  while (!(checkidle(fd) == 1)) {
    nanosleep(wait, NULL);
  }
  printf("Exposure completed!  Image stored in dark buffer.\n");
  return 1;
}


x86 assembly (clang, -O0):
<takedarkimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x81c(%rbp)
lea    -0x840(%rbp),%rdi
mov    $0xc8,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x2,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x4,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x6,%rdi
mov    $0x79,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0xa,%rdi
mov    $0xfa,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0xc,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0xe,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x12,%rdi
mov    $0x1770,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x14,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x16,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x18,%rdi
mov    $0x3,%esi
call   1080 <convint@plt>
lea    -0x840(%rbp),%rdi
add    $0x1a,%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    -0x410(%rbp),%rdi
lea    -0x840(%rbp),%rcx
lea    -0x814(%rbp),%rsi
mov    $0x1,%edx
mov    $0x1c,%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)
jne    12fb <takedarkimage+0x18b>
movzbl -0x810(%rbp),%eax
cmp    $0x6,%eax
je     1313 <takedarkimage+0x1a3>
lea    0xcfe(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137f <takedarkimage+0x20f>
lea    0xcfd(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x848(%rbp)
movl   $0x160dc080,-0x850(%rbp)
c0 0d 16
mov    -0x8(%rbp),%edi
call   1090 <checkidle@plt>
cmp    $0x1,%eax
sete   %al
xor    $0xff,%al
test   $0x1,%al
jne    1351 <takedarkimage+0x1e1>
jmp    136c <takedarkimage+0x1fc>
mov    -0x850(%rbp),%edi
mov    -0x848(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <nanosleep@plt>
jmp    1334 <takedarkimage+0x1c4>
lea    0xcb6(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<takedarkimage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x828,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc8,%esi
call   1080 <convint@plt>
lea    0x2(%rsp),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x6(%rsp),%rdi
mov    $0x79,%esi
call   1080 <convint@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0xa(%rsp),%rdi
mov    $0xfa,%esi
call   1080 <convint@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0xe(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x12(%rsp),%rdi
mov    $0x1770,%esi
call   1080 <convint@plt>
lea    0x14(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x16(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x18(%rsp),%rdi
mov    $0x3,%esi
call   1080 <convint@plt>
lea    0x1a(%rsp),%rdi
xor    %esi,%esi
call   1080 <convint@plt>
lea    0x420(%rsp),%rbp
lea    0x1c(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
mov    $0x1c,%r8d
call   1060 <buildpacket@plt>
mov    0x1c(%rsp),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
call   1070 <listen@plt>
lea    0xd82(%rip),%rbp
cmp    $0x1,%eax
jne    12ca <takedarkimage+0x15a>
cmpb   $0x6,0x20(%rsp)
jne    12ca <takedarkimage+0x15a>
lea    0xd85(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1090 <checkidle@plt>
mov    $0x1,%r15d
lea    0xd7d(%rip),%rbp
cmp    $0x1,%eax
je     12ca <takedarkimage+0x15a>
nop
mov    $0x160dc080,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <nanosleep@plt>
mov    %ebx,%edi
call   1090 <checkidle@plt>
cmp    $0x1,%eax
jne    12b0 <takedarkimage+0x140>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r15d,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [23 x i8] c"Problem taking image.\0A\00"
@.str.1 = [18 x i8] c"Taking image ...\0A\00"
@.str.2 = [51 x i8] c"Exposure completed! Image stored in dark buffer.\0A\00"
define i32 @takedarkimage(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [28 x i8]
%10 = alloca %struct.timespec
store i32 %0, i32* %3
store i32 0, i32* %8
%11 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 0
%12 = call i32 @convint(i8* %11, i32 200)
%13 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 2
%14 = call i32 @convint(i8* %13, i32 0)
%15 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 4
%16 = call i32 @convint(i8* %15, i32 0)
%17 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 6
%18 = call i32 @convint(i8* %17, i32 121)
%19 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 8
%20 = call i32 @convint(i8* %19, i32 0)
%21 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 10
%22 = call i32 @convint(i8* %21, i32 250)
%23 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 12
%24 = call i32 @convint(i8* %23, i32 0)
%25 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 14
%26 = call i32 @convint(i8* %25, i32 0)
%27 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 16
%28 = call i32 @convint(i8* %27, i32 0)
%29 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 18
%30 = call i32 @convint(i8* %29, i32 6000)
%31 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 20
%32 = call i32 @convint(i8* %31, i32 0)
%33 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 22
%34 = call i32 @convint(i8* %33, i32 0)
%35 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 24
%36 = call i32 @convint(i8* %35, i32 3)
%37 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 26
%38 = call i32 @convint(i8* %37, i32 0)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = getelementptr inbounds [28 x i8], [28 x i8]* %9, i64 0, i64 0
%41 = call i32 @buildpacket(i8* %39, i32* %6, i32 1, i8* %40, i32 28)
%42 = load i32, i32* %3
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
%46 = load i32, i32* %3
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%48 = call i32 @listen(i32 %46, i8* %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %56
51: ; preds = %1
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 6
br i1 %55, label %58, label %56
56: ; preds = %51, %1
%57 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %77
58: ; preds = %51
%59 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58
%61 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
store i64 0, i64* %61
%62 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
store i32 370000000, i32* %62
br label %63
63: ; preds = %68, %60
%64 = load i32, i32* %3
%65 = call i32 @checkidle(i32 %64)
%66 = icmp eq i32 %65, 1
%67 = xor i1 %66, true
br i1 %67, label %68, label %75
68: ; preds = %63
%69 = bitcast %struct.timespec* %10 to { i32, i64 }*
%70 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %69, i32 0, i32 1
%73 = load i64, i64* %72
%74 = call i32 @nanosleep(i32 %71, i64 %73, i32* null)
br label %63
75: ; preds = %63
%76 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %77
77: ; preds = %75, %56
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
@str = [22 x i8] c"Problem taking image.\00"
@str.3 = [17 x i8] c"Taking image ...\00"
@str.4 = [50 x i8] c"Exposure completed! Image stored in dark buffer.\00"
define i32 @takedarkimage(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca [28 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 0
%10 = call i32 @convint(i8* %9, i32 200)
%11 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 2
%12 = call i32 @convint(i8* %11, i32 0)
%13 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 4
%14 = call i32 @convint(i8* %13, i32 0)
%15 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 6
%16 = call i32 @convint(i8* %15, i32 121)
%17 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 8
%18 = call i32 @convint(i8* %17, i32 0)
%19 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 10
%20 = call i32 @convint(i8* %19, i32 250)
%21 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 12
%22 = call i32 @convint(i8* %21, i32 0)
%23 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 14
%24 = call i32 @convint(i8* %23, i32 0)
%25 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 16
%26 = call i32 @convint(i8* %25, i32 0)
%27 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 18
%28 = call i32 @convint(i8* %27, i32 6000)
%29 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 20
%30 = call i32 @convint(i8* %29, i32 0)
%31 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 22
%32 = call i32 @convint(i8* %31, i32 0)
%33 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 24
%34 = call i32 @convint(i8* %33, i32 3)
%35 = getelementptr inbounds [28 x i8], [28 x i8]* %5, i64 0, i64 26
%36 = call i32 @convint(i8* %35, i32 0)
%37 = call i32 @buildpacket(i8* %6, i32* %4, i32 1, i8* %9, i32 28)
%38 = load i32, i32* %4
%39 = call i32 @write(i32 %0, i8* %6, i32 %38)
%40 = call i32 @listen(i32 %0, i8* %7)
%41 = icmp eq i32 %40, 1
%42 = load i8, i8* %7
%43 = icmp eq i8 %42, 6
%44 = select i1 %41, i1 %43, i1 false
br i1 %44, label %45, label %53
45: ; preds = %1
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0))
%47 = call i32 @checkidle(i32 %0)
%48 = icmp eq i32 %47, 1
br i1 %48, label %53, label %49
49: ; preds = %45, %49
%50 = call i32 @nanosleep(i32 370000000, i64 0, i32* null)
%51 = call i32 @checkidle(i32 %0)
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %49
53: ; preds = %49, %45, %1
%54 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @str.4, i64 0, i64 0), %45 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @str.4, i64 0, i64 0), %49 ]
%55 = phi i32 [ 0, %1 ], [ 1, %45 ], [ 1, %49 ]
%56 = call i32 @puts(i8* dereferenceable(1) %54)
ret i32 %55
}