#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, int);
int /*<<< orphan*/ omega_suspend();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: apm <option>\n"
           "\t--suspend         Suspend device\n"
           "\t--modem-poweron   Power on modem\n"
           "\t--modem-poweroff  Power off modem\n");
    return 1;
  }
  if (strcmp(argv[1], "--suspend") == 0) {
    omega_suspend();
  } else if (strcmp(argv[1], "--modem-poweron") == 0) {
    int modemFd = open("/dev/omega_bcm2121", O_RDWR);
    ioctl(modemFd, 0x5402, 0);
    ioctl(modemFd, 0x5401, 1);
    close(modemFd);
  } else if (strcmp(argv[1], "--modem-poweroff") == 0) {
    int modemFd = open("/dev/omega_bcm2121", O_RDWR);
    ioctl(modemFd, 0x5403, 2);
    ioctl(modemFd, 0x5401, 1);
    close(modemFd);
  }
  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)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xed5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11c2 <main+0x62>
mov    $0x0,%al
call   1080 <omega_suspend@plt>
jmp    1292 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1226 <main+0xc6>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x5402,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x5401,%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    128d <main+0x12d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1288 <main+0x128>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x5403,%esi
mov    $0x2,%edx
call   1040 <ioctl@plt>
mov    -0x18(%rbp),%edi
mov    $0x5401,%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
jmp    128d <main+0x12d>
jmp    1292 <main+0x132>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11d5 <main+0x75>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e8 <main+0x88>
mov    0x8(%rbx),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f3 <main+0x93>
mov    0x8(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1232 <main+0xd2>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x5403,%esi
mov    $0x2,%edx
jmp    1215 <main+0xb5>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1232 <main+0xd2>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <omega_suspend@plt>
jmp    1232 <main+0xd2>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe17(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %eax,%edi
mov    $0x5402,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %ebp,%edi
mov    $0x5401,%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [124 x i8] c"Usage: apm <option>\0A\09--suspend Suspend device\0A\09--modem-poweron Power on modem\0A\09--modem-poweroff Power off modem\0A\00"
@.str.1 = [10 x i8] c"--suspend\00"
@.str.2 = [16 x i8] c"--modem-poweron\00"
@.str.3 = [19 x i8] c"/dev/omega_bcm2121\00"
@O_RDWR = global i32 0
@.str.4 = [17 x i8] c"--modem-poweroff\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %53
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 (...) @omega_suspend()
br label %52
20: ; preds = %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = call i32 @ioctl(i32 %29, i32 21506, i32 0)
%31 = load i32, i32* %6
%32 = call i32 @ioctl(i32 %31, i32 21505, i32 1)
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
br label %51
35: ; preds = %20
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %50
41: ; preds = %35
%42 = load i32, i32* @O_RDWR
%43 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = call i32 @ioctl(i32 %44, i32 21507, i32 2)
%46 = load i32, i32* %7
%47 = call i32 @ioctl(i32 %46, i32 21505, i32 1)
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %41, %35
br label %51
51: ; preds = %50, %26
br label %52
52: ; preds = %51, %18
store i32 0, i32* %3
br label %53
53: ; preds = %52, %10
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"--suspend\00"
@.str.2 = [16 x i8] c"--modem-poweron\00"
@.str.3 = [19 x i8] c"/dev/omega_bcm2121\00"
@O_RDWR = global i32 0
@.str.4 = [17 x i8] c"--modem-poweroff\00"
@str = [123 x i8] c"Usage: apm <option>\0A\09--suspend Suspend device\0A\09--modem-poweron Power on modem\0A\09--modem-poweroff Power off modem\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([123 x i8], [123 x i8]* @str, i64 0, i64 0))
br label %33
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (...) @omega_suspend()
br label %33
13: ; preds = %6
%14 = load i8*, i8** %7
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @O_RDWR
%19 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = tail call i32 @ioctl(i32 %19, i32 21506, i32 0)
%21 = tail call i32 @ioctl(i32 %19, i32 21505, i32 1)
%22 = tail call i32 @close(i32 %19)
br label %33
23: ; preds = %13
%24 = load i8*, i8** %7
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @O_RDWR
%29 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = tail call i32 @ioctl(i32 %29, i32 21507, i32 2)
%31 = tail call i32 @ioctl(i32 %29, i32 21505, i32 1)
%32 = tail call i32 @close(i32 %29)
br label %33
33: ; preds = %11, %23, %27, %17, %4
%34 = phi i32 [ 1, %4 ], [ 0, %17 ], [ 0, %27 ], [ 0, %23 ], [ 0, %11 ]
ret i32 %34
}