#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*/ O_RDWR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ioctl(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int voltage = atoi(argv[1]);
  int fd, ret = -1;
  int val = 0x2b0010;
  char *devname = "/dev/lnb";
  if ((fd = open(devname, O_RDWR)) < 0) {
    fprintf(stderr, "Could not open %s\n", devname);
    perror(devname);
    exit(1);
  }
  printf("voltage: %d\n", voltage);
  switch (voltage) {
  case 13:
    val = 0x2b0011;
    break;
  case 18:
    val = 0x2b0012;
    break;
  }
  ret = ioctl(fd, val, 0);
  close(fd);
  exit(ret);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x2b0010,-0x20(%rbp)
lea    0xe45(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1209 <main+0x89>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xd,%eax
je     123d <main+0xbd>
jmp    122c <main+0xac>
mov    -0x2c(%rbp),%eax
sub    $0x12,%eax
je     1249 <main+0xc9>
jmp    1250 <main+0xd0>
movl   $0x2b0011,-0x20(%rbp)
jmp    1250 <main+0xd0>
movl   $0x2b0012,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    11d8 <main+0x58>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
lea    0xe42(%rip),%rbx
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
cmp    $0x12,%ebp
sete   %al
add    %eax,%eax
add    $0x2b0010,%eax
cmp    $0xd,%ebp
mov    $0x2b0011,%esi
cmovne %eax,%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/lnb\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@.str.2 = [13 x i8] c"voltage: %d\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
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
store i32 -1, i32* %8
store i32 2818064, i32* %9
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %10
%15 = load i8*, i8** %10
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %10
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %10
%24 = call i32 @perror(i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
switch i32 %29, label %32 [
i32 13, label %30
i32 18, label %31
]
30: ; preds = %26
store i32 2818065, i32* %9
br label %32
31: ; preds = %26
store i32 2818066, i32* %9
br label %32
32: ; preds = %26, %31, %30
%33 = load i32, i32* %7
%34 = load i32, i32* %9
%35 = call i32 @ioctl(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %8
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %8
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/lnb\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@.str.2 = [13 x i8] c"voltage: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%16 = icmp eq i32 %5, 18
%17 = select i1 %16, i32 2818066, i32 2818064
%18 = icmp eq i32 %5, 13
%19 = select i1 %18, i32 2818065, i32 %17
%20 = tail call i32 @ioctl(i32 %7, i32 %19, i32 0)
%21 = tail call i32 @close(i32 %7)
%22 = tail call i32 @exit(i32 %20)
unreachable
}