#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 */
scalar_t__ a_button();
int /*<<< orphan*/ depth_close();
int depth_image_get_height();
int depth_image_get_width();
int /*<<< orphan*/ depth_open();
scalar_t__ depth_update();
int get_depth_value(int, int);
int /*<<< orphan*/ msleep(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (!depth_open()) {
    printf("Unable to open libkipr_link_depth_sensor\n");
    return 1;
  }
  printf("Press the 'A' button for three seconds to stop\n");
  while (a_button() == 0) {
    if (depth_update()) {
      int x_center = depth_image_get_width() / 2;
      int y_center = depth_image_get_height() / 2;
      int depth_center = get_depth_value(x_center, y_center);
      printf("Depth at(%d, %d) is %d\n", x_center, y_center, depth_center);
      msleep(2000);
    } else {
      printf("No depth frame image yet\n");
      msleep(2000);
    }
  }
  depth_close();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <depth_open@plt>
cmp    $0x0,%eax
jne    11d0 <main+0x40>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0xf3>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1040 <a_button@plt>
cmp    $0x0,%rax
jne    1275 <main+0xe5>
mov    $0x0,%al
call   1030 <depth_update@plt>
cmp    $0x0,%rax
je     1258 <main+0xc8>
mov    $0x0,%al
call   1050 <depth_image_get_width@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   10b0 <depth_image_get_height@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1090 <get_depth_value@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x7d0,%edi
call   1070 <msleep@plt>
jmp    1270 <main+0xe0>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x7d0,%edi
call   1070 <msleep@plt>
jmp    11de <main+0x4e>
mov    $0x0,%al
call   10a0 <depth_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1070 <depth_open@plt>
test   %eax,%eax
je     11d7 <main+0x37>
lea    0xe87(%rip),%rdi
call   1050 <puts@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <a_button@plt>
test   %rax,%rax
je     11f5 <main+0x55>
xor    %eax,%eax
call   10b0 <depth_close@plt>
jmp    11e9 <main+0x49>
lea    0xe3a(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe74(%rip),%r14
lea    0xdfd(%rip),%r12
jmp    122e <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x7d0,%edi
call   1080 <msleep@plt>
xor    %eax,%eax
call   1040 <a_button@plt>
test   %rax,%rax
jne    11ce <main+0x2e>
xor    %eax,%eax
call   1030 <depth_update@plt>
test   %rax,%rax
je     1210 <main+0x70>
xor    %eax,%eax
call   1060 <depth_image_get_width@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
xor    %eax,%eax
call   10c0 <depth_image_get_height@plt>
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   10a0 <get_depth_value@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1218 <main+0x78>

LLVM IR (-O0):
@.str = [42 x i8] c"Unable to open libkipr_link_depth_sensor\0A\00"
@.str.1 = [48 x i8] c"Press the 'A' button for three seconds to stop\0A\00"
@.str.2 = [24 x i8] c"Depth at(%d, %d) is %d\0A\00"
@.str.3 = [26 x i8] c"No depth frame image yet\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @depth_open()
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %40
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %37, %13
%16 = call i64 (...) @a_button()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = call i64 (...) @depth_update()
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = call i32 (...) @depth_image_get_width()
%23 = sdiv i32 %22, 2
store i32 %23, i32* %6
%24 = call i32 (...) @depth_image_get_height()
%25 = sdiv i32 %24, 2
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i32 @get_depth_value(i32 %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30, i32 %31)
%33 = call i32 @msleep(i32 2000)
br label %37
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @msleep(i32 2000)
br label %37
37: ; preds = %34, %21
br label %15
38: ; preds = %15
%39 = call i32 (...) @depth_close()
store i32 0, i32* %3
br label %40
40: ; preds = %38, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.2 = [24 x i8] c"Depth at(%d, %d) is %d\0A\00"
@str = [41 x i8] c"Unable to open libkipr_link_depth_sensor\00"
@str.4 = [47 x i8] c"Press the 'A' button for three seconds to stop\00"
@str.5 = [25 x i8] c"No depth frame image yet\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @depth_open()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %29
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.4, i64 0, i64 0))
%9 = tail call i64 (...) @a_button()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %7, %23
%12 = tail call i64 (...) @depth_update()
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = tail call i32 (...) @depth_image_get_width()
%16 = sdiv i32 %15, 2
%17 = tail call i32 (...) @depth_image_get_height()
%18 = sdiv i32 %17, 2
%19 = tail call i32 @get_depth_value(i32 %16, i32 %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %18, i32 %19)
br label %23
21: ; preds = %11
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
%24 = tail call i32 @msleep(i32 2000)
%25 = tail call i64 (...) @a_button()
%26 = icmp eq i64 %25, 0
br i1 %26, label %11, label %27
27: ; preds = %23, %7
%28 = tail call i32 (...) @depth_close()
br label %29
29: ; preds = %27, %5
%30 = phi i32 [ 0, %27 ], [ 1, %5 ]
ret i32 %30
}