#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int getStatus(int);
int ioctl(int, int, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  int nRet, hFile;
  char buff[50];
  memset(buff, 0, sizeof(buff));
  if ((hFile = open("/dev/usb/usbtest", O_RDONLY)) < 0) {
    printf("Error open %d\n", hFile);
    return 0;
  };
  (void)getStatus(hFile);
  printf("Soft reset of device\n");
  if ((nRet = ioctl(hFile, 73)) < 0) {
    printf("Error ioctl %d\n", nRet);
    return 0;
  }
  (void)getStatus(hFile);
  printf("Calibrate controler extended \n");
  *buff = 2;
  if ((nRet = ioctl(hFile, 82, buff)) < 0) {
    printf("Error ioctl %d\n", nRet);
    return 0;
  }
  printf("\n");
  while ((nRet = getStatus(hFile)) < 2) {
    printf("wait for lower left corner %d\n", nRet);
    sleep(1);
  }
  printf("\n");
  while ((nRet = getStatus(hFile)) < 3) {
    printf("lower left corner complited;wait for upper right corner %d\n",
           nRet);
    sleep(1);
  }
  printf("\n");
  if ((nRet = getStatus(hFile)) == 3)
    printf("upper right corner complited %d\n", nRet);
  else
    printf("upper right corner error %d\n", nRet);
  printf(" koniec kalibracji OK ioctl: %d \n", nRet);
  close(hFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1040 <memset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11cd <main+0x5d>
mov    -0xc(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x1ee>
mov    -0xc(%rbp),%edi
call   1050 <getStatus@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0x49,%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    121b <main+0xab>
mov    -0x8(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x1ee>
mov    -0xc(%rbp),%edi
call   1050 <getStatus@plt>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x2,-0x40(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rdx
mov    $0x52,%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1271 <main+0x101>
mov    -0x8(%rbp),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135e <main+0x1ee>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <getStatus@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x2,%eax
jge    12b3 <main+0x143>
mov    -0x8(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    127f <main+0x10f>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <getStatus@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x3,%eax
jge    12f5 <main+0x185>
mov    -0x8(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    12c1 <main+0x151>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <getStatus@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x3,%eax
jne    132d <main+0x1bd>
mov    -0x8(%rbp),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    133e <main+0x1ce>
mov    -0x8(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     12c8 <main+0x138>
mov    %ebx,%edi
call   1070 <getStatus@plt>
lea    0xf19(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x49,%esi
xor    %eax,%eax
call   1080 <ioctl@plt>
test   %eax,%eax
js     12d3 <main+0x143>
mov    %ebx,%edi
call   1070 <getStatus@plt>
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
movb   $0x2,(%rsp)
mov    %rsp,%rdx
mov    %ebx,%edi
mov    $0x52,%esi
xor    %eax,%eax
call   1080 <ioctl@plt>
test   %eax,%eax
js     12d3 <main+0x143>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1070 <getStatus@plt>
cmp    $0x1,%eax
jg     1262 <main+0xd2>
lea    0xdf6(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %ebx,%edi
call   1070 <getStatus@plt>
cmp    $0x2,%eax
jl     1240 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1070 <getStatus@plt>
cmp    $0x2,%eax
jg     12a2 <main+0x112>
lea    0xdd0(%rip),%rbp
nop
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %ebx,%edi
call   1070 <getStatus@plt>
cmp    $0x3,%eax
jl     1280 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1070 <getStatus@plt>
mov    %eax,%ebp
cmp    $0x3,%eax
jne    12e5 <main+0x155>
lea    0xdca(%rip),%rdi
mov    $0x3,%esi
jmp    12ee <main+0x15e>
lea    0xd42(%rip),%rdi
mov    %ebx,%esi
jmp    12dc <main+0x14c>
lea    0xd46(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    130c <main+0x17c>
lea    0xdc0(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/dev/usb/usbtest\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"Error open %d\0A\00"
@.str.2 = [22 x i8] c"Soft reset of device\0A\00"
@.str.3 = [16 x i8] c"Error ioctl %d\0A\00"
@.str.4 = [31 x i8] c"Calibrate controler extended \0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [31 x i8] c"wait for lower left corner %d\0A\00"
@.str.7 = [60 x i8] c"lower left corner complited;wait for upper right corner %d\0A\00"
@.str.8 = [33 x i8] c"upper right corner complited %d\0A\00"
@.str.9 = [29 x i8] c"upper right corner error %d\0A\00"
@.str.10 = [34 x i8] c" koniec kalibracji OK ioctl: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 50)
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 0, i32* %1
br label %71
13: ; preds = %0
%14 = load i32, i32* %3
%15 = call i32 @getStatus(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = call i32 (i32, i32, ...) @ioctl(i32 %17, i32 73)
store i32 %18, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %21)
store i32 0, i32* %1
br label %71
23: ; preds = %13
%24 = load i32, i32* %3
%25 = call i32 @getStatus(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
store i8 2, i8* %27
%28 = load i32, i32* %3
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%30 = call i32 (i32, i32, ...) @ioctl(i32 %28, i32 82, i8* %29)
store i32 %30, i32* %2
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i32, i32* %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 0, i32* %1
br label %71
35: ; preds = %23
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %41, %35
%38 = load i32, i32* %3
%39 = call i32 @getStatus(i32 %38)
store i32 %39, i32* %2
%40 = icmp slt i32 %39, 2
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %2
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = call i32 @sleep(i32 1)
br label %37
45: ; preds = %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %51, %45
%48 = load i32, i32* %3
%49 = call i32 @getStatus(i32 %48)
store i32 %49, i32* %2
%50 = icmp slt i32 %49, 3
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %2
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = call i32 @sleep(i32 1)
br label %47
55: ; preds = %47
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* %3
%58 = call i32 @getStatus(i32 %57)
store i32 %58, i32* %2
%59 = icmp eq i32 %58, 3
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i32, i32* %2
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %61)
br label %66
63: ; preds = %55
%64 = load i32, i32* %2
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63, %60
%67 = load i32, i32* %2
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %3
%70 = call i32 @close(i32 %69)
store i32 0, i32* %1
br label %71
71: ; preds = %66, %32, %20, %10
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@.str = [17 x i8] c"/dev/usb/usbtest\00"
@O_RDONLY = global i32 0
@.str.1 = [15 x i8] c"Error open %d\0A\00"
@.str.3 = [16 x i8] c"Error ioctl %d\0A\00"
@.str.6 = [31 x i8] c"wait for lower left corner %d\0A\00"
@.str.7 = [60 x i8] c"lower left corner complited;wait for upper right corner %d\0A\00"
@.str.8 = [33 x i8] c"upper right corner complited %d\0A\00"
@.str.9 = [29 x i8] c"upper right corner error %d\0A\00"
@.str.10 = [34 x i8] c" koniec kalibracji OK ioctl: %d \0A\00"
@str = [21 x i8] c"Soft reset of device\00"
@str.11 = [30 x i8] c"Calibrate controler extended \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 50)
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %54
9: ; preds = %0
%10 = call i32 @getStatus(i32 %5)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%12 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 73)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %54
16: ; preds = %9
%17 = call i32 @getStatus(i32 %5)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.11, i64 0, i64 0))
store i8 2, i8* %2
%19 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 82, i8* %2)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %54
23: ; preds = %16
%24 = call i32 @putchar(i32 10)
%25 = call i32 @getStatus(i32 %5)
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %33
27: ; preds = %23, %27
%28 = phi i32 [ %31, %27 ], [ %25, %23 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = call i32 @sleep(i32 1)
%31 = call i32 @getStatus(i32 %5)
%32 = icmp slt i32 %31, 2
br i1 %32, label %27, label %33
33: ; preds = %27, %23
%34 = call i32 @putchar(i32 10)
%35 = call i32 @getStatus(i32 %5)
%36 = icmp slt i32 %35, 3
br i1 %36, label %37, label %43
37: ; preds = %33, %37
%38 = phi i32 [ %41, %37 ], [ %35, %33 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.7, i64 0, i64 0), i32 %38)
%40 = call i32 @sleep(i32 1)
%41 = call i32 @getStatus(i32 %5)
%42 = icmp slt i32 %41, 3
br i1 %42, label %37, label %43
43: ; preds = %37, %33
%44 = call i32 @putchar(i32 10)
%45 = call i32 @getStatus(i32 %5)
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 3)
br label %51
49: ; preds = %43
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i32 %45)
br label %51
51: ; preds = %49, %47
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 %45)
%53 = call i32 @close(i32 %5)
br label %54
54: ; preds = %51, %21, %14, %7
ret i32 0
}