#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 input_event {
  int value;
  int /*<<< orphan*/ code;
  void *type;
};
typedef int /*<<< orphan*/ ie;

/* Variables and functions */
void *EV_FF;
int /*<<< orphan*/ FF_AUTOCENTER;
int /*<<< orphan*/ FF_GAIN;
int /*<<< orphan*/ O_RDWR;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int write(int, struct input_event *, int);
int main(int argc, char **argv) {
  int fd;
  const char *device_file_name = "/dev/input/event0";
  int i;
  int gain = -1;
  int autocenter = -1;
  for (i = 1; i < argc; ++i) {
    if (strcmp(argv[i], "--help") == 0) {
      printf(
          "Usage: %s /dev/input/eventXX [-g gain] [-a autocenter_strength]\n",
          argv[0]);
      printf("Sets the gain and the autocenter of a force-feedback device\n");
      printf("Values should belong to 0 to 100\n");
      exit(1);
    } else if (strcmp(argv[i], "-g") == 0) {
      if (++i >= argc) {
        fprintf(stderr, "Missing gain value\n");
        exit(1);
      }
      gain = atoi(argv[i]);
    } else if (strcmp(argv[i], "-a") == 0) {
      if (++i >= argc) {
        fprintf(stderr, "Missing auto-center value\n");
        exit(1);
      }
      autocenter = atoi(argv[i]);
    } else {
      device_file_name = argv[i];
    }
  }
  if (autocenter == -1 && gain == -1) {
    exit(0);
  }
  fd = open(device_file_name, O_RDWR);
  if (fd == -1) {
    perror("Open device file");
    exit(1);
  }
  printf("Device %s opened\n", device_file_name);
  if (autocenter >= 0 && autocenter <= 100) {
    struct input_event ie;
    ie.type = EV_FF;
    ie.code = FF_AUTOCENTER;
    ie.value = 0xFFFFUL * autocenter / 100;
    if (write(fd, &ie, sizeof(ie)) == -1)
      perror("set auto-center");
  }
  if (gain >= 0 && gain <= 100) {
    struct input_event ie;
    ie.type = EV_FF;
    ie.code = FF_GAIN;
    ie.value = 0xFFFFUL * gain / 100;
    if (write(fd, &ie, sizeof(ie)) == -1)
      perror("set gain");
  }
  exit(0);
}


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)
lea    0xe63(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1324 <main+0x1a4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe3d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    128b <main+0x10b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    -0x8(%rbp),%eax
jl     1272 <main+0xf2>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    130c <main+0x18c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe32(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12f7 <main+0x177>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    -0x8(%rbp),%eax
jl     12de <main+0x15e>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    1307 <main+0x187>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    130c <main+0x18c>
jmp    1311 <main+0x191>
jmp    1316 <main+0x196>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b6 <main+0x36>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    133f <main+0x1bf>
cmpl   $0xffffffff,-0x28(%rbp)
jne    133f <main+0x1bf>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1374 <main+0x1f4>
lea    0xd89(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jl     13f7 <main+0x277>
cmpl   $0x64,-0x2c(%rbp)
jg     13f7 <main+0x277>
mov    0x2c1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x2c(%rbp),%rax
imul   $0xffff,%rax,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13f2 <main+0x272>
lea    0xd24(%rip),%rdi
call   1080 <perror@plt>
jmp    13f7 <main+0x277>
cmpl   $0x0,-0x28(%rbp)
jl     1468 <main+0x2e8>
cmpl   $0x64,-0x28(%rbp)
jg     1468 <main+0x2e8>
mov    0x2bae(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2bb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
movslq -0x28(%rbp),%rax
imul   $0xffff,%rax,%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x50(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1463 <main+0x2e3>
lea    0xcc3(%rip),%rdi
call   1080 <perror@plt>
jmp    1468 <main+0x2e8>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     1282 <main+0xf2>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe4d(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%r12d
movl   $0xffffffff,0x8(%rsp)
ff
lea    0xe45(%rip),%r13
lea    0xe86(%rip),%r14
movl   $0xffffffff,0xc(%rsp)
ff
jmp    11f6 <main+0x66>
xchg   %ax,%ax
mov    (%rbx,%r15,8),%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
cmp    %ebp,%r12d
jge    129e <main+0x10e>
movslq %r12d,%r15
mov    (%rbx,%r15,8),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12ea <main+0x15a>
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0xd0>
mov    (%rbx,%r15,8),%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e0 <main+0x50>
add    $0x1,%r12d
cmp    %ebp,%r12d
jge    1409 <main+0x279>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x8(%rsp)
jmp    11e9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12d
cmp    %ebp,%r12d
jge    13f7 <main+0x267>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rdi
call   10a0 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    11e9 <main+0x59>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xd6f(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    0x8(%rsp),%ebx
cmp    $0xffffffff,%ebx
mov    0xc(%rsp),%r15d
jne    12b9 <main+0x129>
cmp    $0xffffffff,%r15d
jne    12b9 <main+0x129>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    131d <main+0x18d>
lea    0xdb4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    (%rbx),%rsi
lea    0xd25(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%r14d
lea    0xd79(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x64,%ebx
ja     138b <main+0x1fb>
mov    0x2c83(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %ebx,%eax
shl    $0x10,%eax
sub    %ebx,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    138b <main+0x1fb>
lea    0xd2c(%rip),%rdi
call   1090 <perror@plt>
cmp    $0x64,%r15d
ja     12b2 <main+0x122>
mov    0x2c24(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
mov    0x2c2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %r15d,%eax
shl    $0x10,%eax
sub    %r15d,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x25,%rax
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    12b2 <main+0x122>
lea    0xcd7(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2bca(%rip),%rax
mov    (%rax),%edi
lea    0xc56(%rip),%rsi
jmp    1419 <main+0x289>
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
lea    0xc5b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i8* }
@.str = [18 x i8] c"/dev/input/event0\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [65 x i8] c"Usage: %s /dev/input/eventXX [-g gain] [-a autocenter_strength]\0A\00"
@.str.3 = [61 x i8] c"Sets the gain and the autocenter of a force-feedback device\0A\00"
@.str.4 = [34 x i8] c"Values should belong to 0 to 100\0A\00"
@.str.5 = [3 x i8] c"-g\00"
@stderr = global i32 0
@.str.6 = [20 x i8] c"Missing gain value\0A\00"
@.str.7 = [3 x i8] c"-a\00"
@.str.8 = [27 x i8] c"Missing auto-center value\0A\00"
@O_RDWR = global i32 0
@.str.9 = [17 x i8] c"Open device file\00"
@.str.10 = [18 x i8] c"Device %s opened\0A\00"
@EV_FF = global i8* null
@FF_AUTOCENTER = global i32 0
@.str.11 = [16 x i8] c"set auto-center\00"
@FF_GAIN = global i32 0
@.str.12 = [9 x i8] c"set gain\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.input_event
%12 = alloca %struct.input_event
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 -1, i32* %9
store i32 -1, i32* %10
store i32 1, i32* %8
br label %13
13: ; preds = %90, %2
%14 = load i32, i32* %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %93
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %17
%34 = load i8**, i8*** %5
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %57
41: ; preds = %33
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
%44 = load i32, i32* %4
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %41
%51 = load i8**, i8*** %5
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
store i32 %56, i32* %9
br label %88
57: ; preds = %33
%58 = load i8**, i8*** %5
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %81
65: ; preds = %57
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
%68 = load i32, i32* %4
%69 = icmp sge i32 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %65
%75 = load i8**, i8*** %5
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @atoi(i8* %79)
store i32 %80, i32* %10
br label %87
81: ; preds = %57
%82 = load i8**, i8*** %5
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
store i8* %86, i8** %7
br label %87
87: ; preds = %81, %74
br label %88
88: ; preds = %87, %50
br label %89
89: ; preds = %88
br label %90
90: ; preds = %89
%91 = load i32, i32* %8
%92 = add nsw i32 %91, 1
store i32 %92, i32* %8
br label %13
93: ; preds = %13
%94 = load i32, i32* %10
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %101
96: ; preds = %93
%97 = load i32, i32* %9
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %96
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %96, %93
%102 = load i8*, i8** %7
%103 = load i32, i32* @O_RDWR
%104 = call i32 @open(i8* %102, i32 %103)
store i32 %104, i32* %6
%105 = load i32, i32* %6
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %110
107: ; preds = %101
%108 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %101
%111 = load i8*, i8** %7
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %111)
%113 = load i32, i32* %10
%114 = icmp sge i32 %113, 0
br i1 %114, label %115, label %135
115: ; preds = %110
%116 = load i32, i32* %10
%117 = icmp sle i32 %116, 100
br i1 %117, label %118, label %135
118: ; preds = %115
%119 = load i8*, i8** @EV_FF
%120 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
store i8* %119, i8** %120
%121 = load i32, i32* @FF_AUTOCENTER
%122 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 %121, i32* %122
%123 = load i32, i32* %10
%124 = sext i32 %123 to i64
%125 = mul i64 65535, %124
%126 = udiv i64 %125, 100
%127 = trunc i64 %126 to i32
%128 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 %127, i32* %128
%129 = load i32, i32* %6
%130 = call i32 @write(i32 %129, %struct.input_event* %11, i32 16)
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %134
132: ; preds = %118
%133 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %134
134: ; preds = %132, %118
br label %135
135: ; preds = %134, %115, %110
%136 = load i32, i32* %9
%137 = icmp sge i32 %136, 0
br i1 %137, label %138, label %158
138: ; preds = %135
%139 = load i32, i32* %9
%140 = icmp sle i32 %139, 100
br i1 %140, label %141, label %158
141: ; preds = %138
%142 = load i8*, i8** @EV_FF
%143 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 2
store i8* %142, i8** %143
%144 = load i32, i32* @FF_GAIN
%145 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 1
store i32 %144, i32* %145
%146 = load i32, i32* %9
%147 = sext i32 %146 to i64
%148 = mul i64 65535, %147
%149 = udiv i64 %148, 100
%150 = trunc i64 %149 to i32
%151 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 0
store i32 %150, i32* %151
%152 = load i32, i32* %6
%153 = call i32 @write(i32 %152, %struct.input_event* %12, i32 16)
%154 = icmp eq i32 %153, -1
br i1 %154, label %155, label %157
155: ; preds = %141
%156 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
br label %157
157: ; preds = %155, %141
br label %158
158: ; preds = %157, %138, %135
%159 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i8* }
@.str = [18 x i8] c"/dev/input/event0\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [65 x i8] c"Usage: %s /dev/input/eventXX [-g gain] [-a autocenter_strength]\0A\00"
@.str.5 = [3 x i8] c"-g\00"
@stderr = global i32 0
@.str.6 = [20 x i8] c"Missing gain value\0A\00"
@.str.7 = [3 x i8] c"-a\00"
@.str.8 = [27 x i8] c"Missing auto-center value\0A\00"
@O_RDWR = global i32 0
@.str.9 = [17 x i8] c"Open device file\00"
@.str.10 = [18 x i8] c"Device %s opened\0A\00"
@EV_FF = global i8* null
@FF_AUTOCENTER = global i32 0
@.str.11 = [16 x i8] c"set auto-center\00"
@FF_GAIN = global i32 0
@.str.12 = [9 x i8] c"set gain\00"
@str = [60 x i8] c"Sets the gain and the autocenter of a force-feedback device\00"
@str.13 = [33 x i8] c"Values should belong to 0 to 100\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.input_event
%4 = alloca %struct.input_event
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %63
6: ; preds = %2, %56
%7 = phi i32 [ %60, %56 ], [ -1, %2 ]
%8 = phi i32 [ %59, %56 ], [ -1, %2 ]
%9 = phi i32 [ %61, %56 ], [ 1, %2 ]
%10 = phi i8* [ %57, %56 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %6
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.13, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %6
%23 = load i8*, i8** %12
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = add nsw i32 %9, 1
%28 = icmp slt i32 %27, %0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = sext i32 %27 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 @atoi(i8* %36)
br label %56
38: ; preds = %22
%39 = load i8*, i8** %12
%40 = tail call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = add nsw i32 %9, 1
%44 = icmp slt i32 %43, %0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %42
%50 = sext i32 %43 to i64
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i8*, i8** %51
%53 = tail call i32 @atoi(i8* %52)
br label %56
54: ; preds = %38
%55 = load i8*, i8** %12
br label %56
56: ; preds = %49, %54, %33
%57 = phi i8* [ %10, %33 ], [ %10, %49 ], [ %55, %54 ]
%58 = phi i32 [ %27, %33 ], [ %43, %49 ], [ %9, %54 ]
%59 = phi i32 [ %37, %33 ], [ %8, %49 ], [ %8, %54 ]
%60 = phi i32 [ %7, %33 ], [ %53, %49 ], [ %7, %54 ]
%61 = add nsw i32 %58, 1
%62 = icmp slt i32 %61, %0
br i1 %62, label %6, label %63
63: ; preds = %56, %2
%64 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %2 ], [ %57, %56 ]
%65 = phi i32 [ -1, %2 ], [ %59, %56 ]
%66 = phi i32 [ -1, %2 ], [ %60, %56 ]
%67 = icmp eq i32 %66, -1
%68 = icmp eq i32 %65, -1
%69 = select i1 %67, i1 %68, i1 false
br i1 %69, label %70, label %72
70: ; preds = %63
%71 = tail call i32 @exit(i32 0)
unreachable
72: ; preds = %63
%73 = load i32, i32* @O_RDWR
%74 = tail call i32 @open(i8* %64, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%78 = tail call i32 @exit(i32 1)
unreachable
79: ; preds = %72
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %64)
%81 = icmp ult i32 %66, 101
br i1 %81, label %82, label %96
82: ; preds = %79
%83 = bitcast %struct.input_event* %3 to i8*
%84 = load i8*, i8** @EV_FF
%85 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
store i8* %84, i8** %85
%86 = load i32, i32* @FF_AUTOCENTER
%87 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
store i32 %86, i32* %87
%88 = mul nuw nsw i32 %66, 65535
%89 = udiv i32 %88, 100
%90 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
store i32 %89, i32* %90
%91 = call i32 @write(i32 %74, %struct.input_event* %3, i32 16)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %82
%94 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %95
95: ; preds = %93, %82
br label %96
96: ; preds = %95, %79
%97 = icmp ult i32 %65, 101
br i1 %97, label %98, label %112
98: ; preds = %96
%99 = bitcast %struct.input_event* %4 to i8*
%100 = load i8*, i8** @EV_FF
%101 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
store i8* %100, i8** %101
%102 = load i32, i32* @FF_GAIN
%103 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
store i32 %102, i32* %103
%104 = mul nuw nsw i32 %65, 65535
%105 = udiv i32 %104, 100
%106 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
store i32 %105, i32* %106
%107 = call i32 @write(i32 %74, %struct.input_event* %4, i32 16)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %111
109: ; preds = %98
%110 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
br label %111
111: ; preds = %109, %98
br label %112
112: ; preds = %111, %96
%113 = tail call i32 @exit(i32 0)
unreachable
}