#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*/ DBG(int, char *);
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
unsigned char *malloc(int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ pixma_activate(int);
int /*<<< orphan*/ pixma_adf_is_ready();
int /*<<< orphan*/ pixma_calibration();
int /*<<< orphan*/ pixma_close();
int /*<<< orphan*/ pixma_gamma(int);
int /*<<< orphan*/ pixma_get_img(unsigned char *);
int /*<<< orphan*/ pixma_init();
scalar_t__ pixma_is_warming_up();
scalar_t__ pixma_open();
int /*<<< orphan*/ pixma_scan();
int /*<<< orphan*/ pixma_scan_mode();
int /*<<< orphan*/ pixma_set_adf(int);
int /*<<< orphan*/ pixma_set_monochrome(int);
scalar_t__ pixma_set_resolution(int);
int /*<<< orphan*/ pixma_set_window(int, int, int, int);
int /*<<< orphan*/ pixma_setup();
int /*<<< orphan*/ set_verbosity(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strdup(int /*<<< orphan*/);
int testAdf();
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write_pnm(unsigned char *, int, int, char *);
int main(int argc, char **argv) {
  unsigned char *img = NULL;
  char *outfile = NULL;
  int calibration = 0;
  int resolution = 75;
  int monochrome = 0;
  int adf = 0;
  int x = 0;
  int y = 0;
  int width = 0;
  int height = 0;
  int opt;
  while ((opt = getopt(argc, argv, "r:x:y:w:h:tcamv:o:")) != -1) {
    switch (opt) {
    case 'r':
      resolution = atoi(optarg);
      break;
    case 'x':
      x = atoi(optarg);
      break;
    case 'y':
      y = atoi(optarg);
      break;
    case 'w':
      width = atoi(optarg);
      break;
    case 'h':
      height = atoi(optarg);
      break;
    case 't':
      return testAdf();
      break;
    case 'c':
      calibration = 1;
      break;
    case 'a':
      adf = 1;
      break;
    case 'm':
      monochrome = 1;
      break;
    case 'v':
      set_verbosity(atoi(optarg));
      break;
    case 'o':
      outfile = strdup(optarg);
      break;
    default:
      usage();
    }
  }
  if (!outfile)
    usage();
  if (!width)
    width = (resolution / 75) * 638 - x;
  if (!height)
    height = (resolution / 75) * 877 - y;
  if (pixma_open() < 0) {
    fprintf(stderr, "Could not connect to scanner\n");
    exit(EXIT_FAILURE);
  }
  pixma_init();
  if (adf && !pixma_adf_is_ready()) {
    fprintf(stderr, "There is no sheet in the ADF\n");
    exit(EXIT_FAILURE);
  }
  if (pixma_set_resolution(resolution) < 0) {
    fprintf(stderr, "Resolution is not supported\n");
    exit(EXIT_FAILURE);
  }
  if (adf && !pixma_adf_is_ready()) {
    fprintf(stderr, "There is no sheet in the ADF\n");
    exit(EXIT_FAILURE);
  }
  pixma_activate(1);
  if (calibration)
    pixma_calibration();
  pixma_scan_mode();
  pixma_set_monochrome(monochrome);
  pixma_set_adf(adf);
  pixma_set_window(x, y, width, height);
  pixma_setup();
  pixma_gamma(1);
  pixma_scan();
  if (pixma_is_warming_up()) {
    DBG(1, "Lamp warmup in progress...\n");
    sleep(15);
  }
  img = malloc(3 * width * height);
  pixma_get_img(img);
  pixma_close();
  write_pnm(img, width, height, outfile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x4b,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd38(%rip),%rdx
call   1170 <getopt@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     1444 <main+0x184>
mov    -0x44(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x18,%eax
ja     1438 <main+0x178>
mov    -0x50(%rbp),%rax
lea    0xca3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    143f <main+0x17f>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    143f <main+0x17f>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,-0x38(%rbp)
jmp    143f <main+0x17f>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,-0x3c(%rbp)
jmp    143f <main+0x17f>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,-0x40(%rbp)
jmp    143f <main+0x17f>
mov    $0x0,%al
call   10e0 <testAdf@plt>
mov    %eax,-0x4(%rbp)
jmp    1649 <main+0x389>
movl   $0x1,-0x24(%rbp)
jmp    143f <main+0x17f>
movl   $0x1,-0x30(%rbp)
jmp    143f <main+0x17f>
movl   $0x1,-0x2c(%rbp)
jmp    143f <main+0x17f>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
call   1190 <atoi@plt>
mov    %eax,%edi
call   10a0 <set_verbosity@plt>
jmp    143f <main+0x17f>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
call   11b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    143f <main+0x17f>
mov    $0x0,%al
call   1150 <usage@plt>
jmp    131e <main+0x5e>
cmpq   $0x0,-0x20(%rbp)
jne    1456 <main+0x196>
mov    $0x0,%al
call   1150 <usage@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    1477 <main+0x1b7>
mov    -0x28(%rbp),%eax
mov    $0x4b,%ecx
cltd
idiv   %ecx
imul   $0x27e,%eax,%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1498 <main+0x1d8>
mov    -0x28(%rbp),%eax
mov    $0x4b,%ecx
cltd
idiv   %ecx
imul   $0x36d,%eax,%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   11e0 <pixma_open@plt>
cmp    $0x0,%rax
jge    14cc <main+0x20c>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    0xbbe(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
call   11a0 <exit@plt>
mov    $0x0,%al
call   11c0 <pixma_init@plt>
cmpl   $0x0,-0x30(%rbp)
je     1510 <main+0x250>
mov    $0x0,%al
call   1090 <pixma_adf_is_ready@plt>
cmp    $0x0,%eax
jne    1510 <main+0x250>
mov    0x2ae4(%rip),%rax
mov    (%rax),%edi
lea    0xb98(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%edi
call   11a0 <exit@plt>
mov    -0x28(%rbp),%edi
call   10b0 <pixma_set_resolution@plt>
cmp    $0x0,%rax
jge    1545 <main+0x285>
mov    0x2aaf(%rip),%rax
mov    (%rax),%edi
lea    0xb81(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
call   11a0 <exit@plt>
cmpl   $0x0,-0x30(%rbp)
je     1582 <main+0x2c2>
mov    $0x0,%al
call   1090 <pixma_adf_is_ready@plt>
cmp    $0x0,%eax
jne    1582 <main+0x2c2>
mov    0x2a72(%rip),%rax
mov    (%rax),%edi
lea    0xb26(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2a55(%rip),%rax
mov    (%rax),%edi
call   11a0 <exit@plt>
mov    $0x1,%edi
call   1110 <pixma_activate@plt>
cmpl   $0x0,-0x24(%rbp)
je     159d <main+0x2dd>
mov    $0x0,%al
call   1120 <pixma_calibration@plt>
mov    $0x0,%al
call   10d0 <pixma_scan_mode@plt>
mov    -0x2c(%rbp),%edi
call   1070 <pixma_set_monochrome@plt>
mov    -0x30(%rbp),%edi
call   1060 <pixma_set_adf@plt>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
call   1140 <pixma_set_window@plt>
mov    $0x0,%al
call   1050 <pixma_setup@plt>
mov    $0x1,%edi
call   1130 <pixma_gamma@plt>
mov    $0x0,%al
call   1160 <pixma_scan@plt>
mov    $0x0,%al
call   1040 <pixma_is_warming_up@plt>
cmp    $0x0,%rax
je     1609 <main+0x349>
mov    $0x1,%edi
lea    0xad6(%rip),%rsi
call   1080 <DBG@plt>
mov    $0xf,%edi
call   11d0 <sleep@plt>
imul   $0x3,-0x3c(%rbp),%edi
imul   -0x40(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1100 <pixma_get_img@plt>
mov    $0x0,%al
call   1180 <pixma_close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <write_pnm@plt>
mov    0x2984(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
movl   $0x4b,0x4(%rsp)
lea    0xd81(%rip),%r13
lea    0xd16(%rip),%rbx
mov    0x2d07(%rip),%r15
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   11b0 <strdup@plt>
mov    %rax,0x20(%rsp)
mov    %ebp,%eax
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    %r14d,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1170 <getopt@plt>
lea    -0x61(%rax),%ecx
cmp    $0x18,%ecx
ja     13ee <main+0x12e>
mov    $0x1,%eax
movslq (%rbx,%rcx,4),%rcx
add    %rbx,%rcx
jmp    *%rcx
movl   $0x1,0x14(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,0x18(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
movl   $0x1,0xc(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,%edi
call   10a0 <set_verbosity@plt>
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,0x1c(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
mov    (%r15),%edi
call   1190 <atoi@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%eax
jmp    1340 <main+0x80>
cmp    $0xffffffff,%eax
je     1416 <main+0x156>
xor    %eax,%eax
call   1150 <usage@plt>
mov    %ebp,%eax
jmp    1340 <main+0x80>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10e0 <testAdf@plt>
mov    0x20(%rsp),%r14
test   %r14,%r14
jne    1427 <main+0x167>
xor    %eax,%eax
call   1150 <usage@plt>
mov    0x1c(%rsp),%r15d
test   %r15d,%r15d
mov    0x18(%rsp),%r12d
mov    0x14(%rsp),%ebx
mov    0x10(%rsp),%r13d
je     14a4 <main+0x1e4>
test   %r12d,%r12d
je     14d0 <main+0x210>
xor    %eax,%eax
call   11e0 <pixma_open@plt>
test   %rax,%rax
js     15d3 <main+0x313>
xor    %eax,%eax
call   11c0 <pixma_init@plt>
test   %ebx,%ebx
je     14fa <main+0x23a>
xor    %eax,%eax
call   1090 <pixma_adf_is_ready@plt>
test   %eax,%eax
je     148f <main+0x1cf>
mov    0x4(%rsp),%edi
call   10b0 <pixma_set_resolution@plt>
test   %rax,%rax
js     15e5 <main+0x325>
xor    %eax,%eax
call   1090 <pixma_adf_is_ready@plt>
test   %eax,%eax
jne    150c <main+0x24c>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
lea    0xbf6(%rip),%rsi
jmp    15f5 <main+0x335>
movslq 0x4(%rsp),%rax
imul   $0x1b4e81b5,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
imul   $0x27e,%eax,%r15d
sub    %r13d,%r15d
test   %r12d,%r12d
jne    1448 <main+0x188>
movslq 0x4(%rsp),%rax
imul   $0x1b4e81b5,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
imul   $0x36d,%eax,%r12d
sub    0x8(%rsp),%r12d
jmp    1448 <main+0x188>
mov    0x4(%rsp),%edi
call   10b0 <pixma_set_resolution@plt>
test   %rax,%rax
js     15e5 <main+0x325>
mov    $0x1,%edi
call   1110 <pixma_activate@plt>
test   %ebp,%ebp
je     1521 <main+0x261>
xor    %eax,%eax
call   1120 <pixma_calibration@plt>
xor    %eax,%eax
call   10d0 <pixma_scan_mode@plt>
mov    0xc(%rsp),%edi
call   1070 <pixma_set_monochrome@plt>
mov    %ebx,%edi
call   1060 <pixma_set_adf@plt>
mov    %r13d,%edi
mov    0x8(%rsp),%esi
mov    %r15d,%edx
mov    %r12d,%ecx
call   1140 <pixma_set_window@plt>
xor    %eax,%eax
call   1050 <pixma_setup@plt>
mov    $0x1,%edi
call   1130 <pixma_gamma@plt>
xor    %eax,%eax
call   1160 <pixma_scan@plt>
xor    %eax,%eax
call   1040 <pixma_is_warming_up@plt>
test   %rax,%rax
je     1589 <main+0x2c9>
lea    0xb5b(%rip),%rsi
mov    $0x1,%edi
call   1080 <DBG@plt>
mov    $0xf,%edi
call   11d0 <sleep@plt>
mov    %r15d,%eax
imul   %r12d,%eax
lea    (%rax,%rax,2),%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1100 <pixma_get_img@plt>
xor    %eax,%eax
call   1180 <pixma_close@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1030 <write_pnm@plt>
mov    0x2a06(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x29fe(%rip),%rax
mov    (%rax),%edi
lea    0xa94(%rip),%rsi
jmp    15f5 <main+0x335>
mov    0x29ec(%rip),%rax
mov    (%rax),%edi
lea    0xabe(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x29cf(%rip),%rax
mov    (%rax),%edi
call   11a0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"r:x:y:w:h:tcamv:o:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not connect to scanner\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [30 x i8] c"There is no sheet in the ADF\0A\00"
@.str.3 = [29 x i8] c"Resolution is not supported\0A\00"
@.str.4 = [28 x i8] c"Lamp warmup in progress...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
store i32 75, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
br label %17
17: ; preds = %53, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %16
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %54
22: ; preds = %17
%23 = load i32, i32* %16
switch i32 %23, label %51 [
i32 114, label %24
i32 120, label %27
i32 121, label %30
i32 119, label %33
i32 104, label %36
i32 116, label %39
i32 99, label %41
i32 97, label %42
i32 109, label %43
i32 118, label %44
i32 111, label %48
]
24: ; preds = %22
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %9
br label %53
27: ; preds = %22
%28 = load i32, i32* @optarg
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %12
br label %53
30: ; preds = %22
%31 = load i32, i32* @optarg
%32 = call i32 @atoi(i32 %31)
store i32 %32, i32* %13
br label %53
33: ; preds = %22
%34 = load i32, i32* @optarg
%35 = call i32 @atoi(i32 %34)
store i32 %35, i32* %14
br label %53
36: ; preds = %22
%37 = load i32, i32* @optarg
%38 = call i32 @atoi(i32 %37)
store i32 %38, i32* %15
br label %53
39: ; preds = %22
%40 = call i32 (...) @testAdf()
store i32 %40, i32* %3
br label %157
41: ; preds = %22
store i32 1, i32* %8
br label %53
42: ; preds = %22
store i32 1, i32* %11
br label %53
43: ; preds = %22
store i32 1, i32* %10
br label %53
44: ; preds = %22
%45 = load i32, i32* @optarg
%46 = call i32 @atoi(i32 %45)
%47 = call i32 @set_verbosity(i32 %46)
br label %53
48: ; preds = %22
%49 = load i32, i32* @optarg
%50 = call i8* @strdup(i32 %49)
store i8* %50, i8** %7
br label %53
51: ; preds = %22
%52 = call i32 (...) @usage()
br label %53
53: ; preds = %51, %48, %44, %43, %42, %41, %36, %33, %30, %27, %24
br label %17
54: ; preds = %17
%55 = load i8*, i8** %7
%56 = icmp ne i8* %55, null
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 (...) @usage()
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* %14
%61 = icmp ne i32 %60, 0
br i1 %61, label %68, label %62
62: ; preds = %59
%63 = load i32, i32* %9
%64 = sdiv i32 %63, 75
%65 = mul nsw i32 %64, 638
%66 = load i32, i32* %12
%67 = sub nsw i32 %65, %66
store i32 %67, i32* %14
br label %68
68: ; preds = %62, %59
%69 = load i32, i32* %15
%70 = icmp ne i32 %69, 0
br i1 %70, label %77, label %71
71: ; preds = %68
%72 = load i32, i32* %9
%73 = sdiv i32 %72, 75
%74 = mul nsw i32 %73, 877
%75 = load i32, i32* %13
%76 = sub nsw i32 %74, %75
store i32 %76, i32* %15
br label %77
77: ; preds = %71, %68
%78 = call i64 (...) @pixma_open()
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %77
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %77
%86 = call i32 (...) @pixma_init()
%87 = load i32, i32* %11
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %97
89: ; preds = %85
%90 = call i32 (...) @pixma_adf_is_ready()
%91 = icmp ne i32 %90, 0
br i1 %91, label %97, label %92
92: ; preds = %89
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%95 = load i32, i32* @EXIT_FAILURE
%96 = call i32 @exit(i32 %95)
unreachable
97: ; preds = %89, %85
%98 = load i32, i32* %9
%99 = call i64 @pixma_set_resolution(i32 %98)
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %106
101: ; preds = %97
%102 = load i32, i32* @stderr
%103 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %97
%107 = load i32, i32* %11
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %117
109: ; preds = %106
%110 = call i32 (...) @pixma_adf_is_ready()
%111 = icmp ne i32 %110, 0
br i1 %111, label %117, label %112
112: ; preds = %109
%113 = load i32, i32* @stderr
%114 = call i32 @fprintf(i32 %113, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%115 = load i32, i32* @EXIT_FAILURE
%116 = call i32 @exit(i32 %115)
unreachable
117: ; preds = %109, %106
%118 = call i32 @pixma_activate(i32 1)
%119 = load i32, i32* %8
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 (...) @pixma_calibration()
br label %123
123: ; preds = %121, %117
%124 = call i32 (...) @pixma_scan_mode()
%125 = load i32, i32* %10
%126 = call i32 @pixma_set_monochrome(i32 %125)
%127 = load i32, i32* %11
%128 = call i32 @pixma_set_adf(i32 %127)
%129 = load i32, i32* %12
%130 = load i32, i32* %13
%131 = load i32, i32* %14
%132 = load i32, i32* %15
%133 = call i32 @pixma_set_window(i32 %129, i32 %130, i32 %131, i32 %132)
%134 = call i32 (...) @pixma_setup()
%135 = call i32 @pixma_gamma(i32 1)
%136 = call i32 (...) @pixma_scan()
%137 = call i64 (...) @pixma_is_warming_up()
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %142
139: ; preds = %123
%140 = call i32 @DBG(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%141 = call i32 @sleep(i32 15)
br label %142
142: ; preds = %139, %123
%143 = load i32, i32* %14
%144 = mul nsw i32 3, %143
%145 = load i32, i32* %15
%146 = mul nsw i32 %144, %145
%147 = call i8* @malloc(i32 %146)
store i8* %147, i8** %6
%148 = load i8*, i8** %6
%149 = call i32 @pixma_get_img(i8* %148)
%150 = call i32 (...) @pixma_close()
%151 = load i8*, i8** %6
%152 = load i32, i32* %14
%153 = load i32, i32* %15
%154 = load i8*, i8** %7
%155 = call i32 @write_pnm(i8* %151, i32 %152, i32 %153, i8* %154)
%156 = load i32, i32* @EXIT_SUCCESS
store i32 %156, i32* %3
br label %157
157: ; preds = %142, %39
%158 = load i32, i32* %3
ret i32 %158
}

LLVM IR (-O2):
@.str = [19 x i8] c"r:x:y:w:h:tcamv:o:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not connect to scanner\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [30 x i8] c"There is no sheet in the ADF\0A\00"
@.str.3 = [29 x i8] c"Resolution is not supported\0A\00"
@.str.4 = [28 x i8] c"Lamp warmup in progress...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %14, %2
%4 = phi i8* [ null, %2 ], [ %15, %14 ]
%5 = phi i32 [ 0, %2 ], [ %16, %14 ]
%6 = phi i32 [ 75, %2 ], [ %17, %14 ]
%7 = phi i32 [ 0, %2 ], [ %18, %14 ]
%8 = phi i32 [ 0, %2 ], [ %19, %14 ]
%9 = phi i32 [ 0, %2 ], [ %20, %14 ]
%10 = phi i32 [ 0, %2 ], [ %21, %14 ]
%11 = phi i32 [ 0, %2 ], [ %22, %14 ]
%12 = phi i32 [ 0, %2 ], [ %23, %14 ]
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %50 [
i32 -1, label %52
i32 114, label %24
i32 120, label %27
i32 121, label %30
i32 119, label %33
i32 104, label %36
i32 116, label %39
i32 99, label %14
i32 97, label %41
i32 109, label %42
i32 118, label %43
i32 111, label %47
]
14: ; preds = %3, %50, %47, %43, %42, %41, %36, %33, %30, %27, %24
%15 = phi i8* [ %4, %50 ], [ %49, %47 ], [ %4, %43 ], [ %4, %42 ], [ %4, %41 ], [ %4, %36 ], [ %4, %33 ], [ %4, %30 ], [ %4, %27 ], [ %4, %24 ], [ %4, %3 ]
%16 = phi i32 [ %5, %50 ], [ %5, %47 ], [ %5, %43 ], [ %5, %42 ], [ %5, %41 ], [ %5, %36 ], [ %5, %33 ], [ %5, %30 ], [ %5, %27 ], [ %5, %24 ], [ 1, %3 ]
%17 = phi i32 [ %6, %50 ], [ %6, %47 ], [ %6, %43 ], [ %6, %42 ], [ %6, %41 ], [ %6, %36 ], [ %6, %33 ], [ %6, %30 ], [ %6, %27 ], [ %26, %24 ], [ %6, %3 ]
%18 = phi i32 [ %7, %50 ], [ %7, %47 ], [ %7, %43 ], [ 1, %42 ], [ %7, %41 ], [ %7, %36 ], [ %7, %33 ], [ %7, %30 ], [ %7, %27 ], [ %7, %24 ], [ %7, %3 ]
%19 = phi i32 [ %8, %50 ], [ %8, %47 ], [ %8, %43 ], [ %8, %42 ], [ 1, %41 ], [ %8, %36 ], [ %8, %33 ], [ %8, %30 ], [ %8, %27 ], [ %8, %24 ], [ %8, %3 ]
%20 = phi i32 [ %9, %50 ], [ %9, %47 ], [ %9, %43 ], [ %9, %42 ], [ %9, %41 ], [ %9, %36 ], [ %9, %33 ], [ %9, %30 ], [ %29, %27 ], [ %9, %24 ], [ %9, %3 ]
%21 = phi i32 [ %10, %50 ], [ %10, %47 ], [ %10, %43 ], [ %10, %42 ], [ %10, %41 ], [ %10, %36 ], [ %10, %33 ], [ %32, %30 ], [ %10, %27 ], [ %10, %24 ], [ %10, %3 ]
%22 = phi i32 [ %11, %50 ], [ %11, %47 ], [ %11, %43 ], [ %11, %42 ], [ %11, %41 ], [ %11, %36 ], [ %35, %33 ], [ %11, %30 ], [ %11, %27 ], [ %11, %24 ], [ %11, %3 ]
%23 = phi i32 [ %12, %50 ], [ %12, %47 ], [ %12, %43 ], [ %12, %42 ], [ %12, %41 ], [ %38, %36 ], [ %12, %33 ], [ %12, %30 ], [ %12, %27 ], [ %12, %24 ], [ %12, %3 ]
br label %3
24: ; preds = %3
%25 = load i32, i32* @optarg
%26 = tail call i32 @atoi(i32 %25)
br label %14
27: ; preds = %3
%28 = load i32, i32* @optarg
%29 = tail call i32 @atoi(i32 %28)
br label %14
30: ; preds = %3
%31 = load i32, i32* @optarg
%32 = tail call i32 @atoi(i32 %31)
br label %14
33: ; preds = %3
%34 = load i32, i32* @optarg
%35 = tail call i32 @atoi(i32 %34)
br label %14
36: ; preds = %3
%37 = load i32, i32* @optarg
%38 = tail call i32 @atoi(i32 %37)
br label %14
39: ; preds = %3
%40 = tail call i32 (...) @testAdf()
br label %134
41: ; preds = %3
br label %14
42: ; preds = %3
br label %14
43: ; preds = %3
%44 = load i32, i32* @optarg
%45 = tail call i32 @atoi(i32 %44)
%46 = tail call i32 @set_verbosity(i32 %45)
br label %14
47: ; preds = %3
%48 = load i32, i32* @optarg
%49 = tail call i8* @strdup(i32 %48)
br label %14
50: ; preds = %3
%51 = tail call i32 (...) @usage()
br label %14
52: ; preds = %3
%53 = icmp eq i8* %4, null
br i1 %53, label %54, label %56
54: ; preds = %52
%55 = tail call i32 (...) @usage()
br label %56
56: ; preds = %54, %52
%57 = icmp eq i32 %11, 0
br i1 %57, label %58, label %62
58: ; preds = %56
%59 = sdiv i32 %6, 75
%60 = mul nsw i32 %59, 638
%61 = sub nsw i32 %60, %9
br label %62
62: ; preds = %58, %56
%63 = phi i32 [ %11, %56 ], [ %61, %58 ]
%64 = icmp eq i32 %12, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = sdiv i32 %6, 75
%67 = mul nsw i32 %66, 877
%68 = sub nsw i32 %67, %10
br label %69
69: ; preds = %65, %62
%70 = phi i32 [ %12, %62 ], [ %68, %65 ]
%71 = tail call i64 (...) @pixma_open()
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = tail call i32 @exit(i32 %76)
unreachable
78: ; preds = %69
%79 = tail call i32 (...) @pixma_init()
%80 = icmp eq i32 %8, 0
br i1 %80, label %89, label %81
81: ; preds = %78
%82 = tail call i32 (...) @pixma_adf_is_ready()
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %92
84: ; preds = %81
%85 = load i32, i32* @stderr
%86 = tail call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = tail call i32 @exit(i32 %87)
unreachable
89: ; preds = %78
%90 = tail call i64 @pixma_set_resolution(i32 %6)
%91 = icmp slt i64 %90, 0
br i1 %91, label %95, label %108
92: ; preds = %81
%93 = tail call i64 @pixma_set_resolution(i32 %6)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %100
95: ; preds = %92, %89
%96 = load i32, i32* @stderr
%97 = tail call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%98 = load i32, i32* @EXIT_FAILURE
%99 = tail call i32 @exit(i32 %98)
unreachable
100: ; preds = %92
%101 = tail call i32 (...) @pixma_adf_is_ready()
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %108
103: ; preds = %100
%104 = load i32, i32* @stderr
%105 = tail call i32 @fprintf(i32 %104, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
%107 = tail call i32 @exit(i32 %106)
unreachable
108: ; preds = %89, %100
%109 = tail call i32 @pixma_activate(i32 1)
%110 = icmp eq i32 %5, 0
br i1 %110, label %113, label %111
111: ; preds = %108
%112 = tail call i32 (...) @pixma_calibration()
br label %113
113: ; preds = %111, %108
%114 = tail call i32 (...) @pixma_scan_mode()
%115 = tail call i32 @pixma_set_monochrome(i32 %7)
%116 = tail call i32 @pixma_set_adf(i32 %8)
%117 = tail call i32 @pixma_set_window(i32 %9, i32 %10, i32 %63, i32 %70)
%118 = tail call i32 (...) @pixma_setup()
%119 = tail call i32 @pixma_gamma(i32 1)
%120 = tail call i32 (...) @pixma_scan()
%121 = tail call i64 (...) @pixma_is_warming_up()
%122 = icmp eq i64 %121, 0
br i1 %122, label %126, label %123
123: ; preds = %113
%124 = tail call i32 @DBG(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%125 = tail call i32 @sleep(i32 15)
br label %126
126: ; preds = %123, %113
%127 = mul nsw i32 %63, 3
%128 = mul nsw i32 %127, %70
%129 = tail call i8* @malloc(i32 %128)
%130 = tail call i32 @pixma_get_img(i8* %129)
%131 = tail call i32 (...) @pixma_close()
%132 = tail call i32 @write_pnm(i8* %129, i32 %63, i32 %70, i8* %4)
%133 = load i32, i32* @EXIT_SUCCESS
br label %134
134: ; preds = %126, %39
%135 = phi i32 [ %40, %39 ], [ %133, %126 ]
ret i32 %135
}