#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int inl(int);
int /*<<< orphan*/ iopl(int);
int /*<<< orphan*/ outl(unsigned int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int nargs, char **argv) {
  unsigned int val;
  unsigned int gpio;
  unsigned int new;
  if (nargs != 3)
    usage();
  gpio = atoi(argv[1]);
  new = atoi(argv[2]);
  if ((gpio != 39) && (gpio < 32 || gpio > 37)) {
    fprintf(stderr, "Error: invalid GPIO port (%s)\n", argv[1]);
    exit(0);
  }
  if (new > 1) {
    fprintf(stderr, "Error: VAL not in {0,1}: (%s)\n", argv[2]);
    exit(0);
  }
  iopl(3);
  val = inl(0xf410 + 0x4);
  if (new) {
    fprintf(stderr, "on\n");
    val = val | (1 << (gpio - 32));
  } else {
    fprintf(stderr, "off\n");
    val = val & ~(1 << (gpio - 32));
  }
  outl(val, 0xf410);
  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   $0x3,-0x8(%rbp)
je     1197 <main+0x27>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x27,-0x18(%rbp)
je     11fb <main+0x8b>
cmpl   $0x20,-0x18(%rbp)
jb     11d5 <main+0x65>
cmpl   $0x25,-0x18(%rbp)
jbe    11fb <main+0x8b>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
cmpl   $0x1,-0x1c(%rbp)
jbe    122b <main+0xbb>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x3,%edi
call   1030 <iopl@plt>
mov    $0xf414,%edi
call   1060 <inl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     127f <main+0x10f>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x20,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    12b0 <main+0x140>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x20,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0xf410,%esi
call   1040 <outl@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
je     1186 <main+0x16>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x8(%rbp),%r15
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rbp
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    -0x20(%rbx),%eax
cmp    $0x6,%eax
jae    121c <main+0xac>
cmp    $0x2,%r14d
jae    1236 <main+0xc6>
mov    $0x3,%edi
call   1030 <iopl@plt>
mov    $0xf414,%edi
call   1060 <inl@plt>
mov    %eax,%ebp
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
test   %r14d,%r14d
je     11ef <main+0x7f>
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xe0,%bl
bts    %ebx,%ebp
jmp    1203 <main+0x93>
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0xe0,%bl
btr    %ebx,%ebp
mov    %ebp,%edi
mov    $0xf410,%esi
call   1040 <outl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x27,%ebx
je     11ab <main+0x3b>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    %r15,%rdx
jmp    1249 <main+0xd9>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Error: invalid GPIO port (%s)\0A\00"
@.str.1 = [31 x i8] c"Error: VAL not in {0,1}: (%s)\0A\00"
@.str.2 = [4 x i8] c"on\0A\00"
@.str.3 = [5 x i8] c"off\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %7
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 39
br i1 %23, label %24, label %37
24: ; preds = %13
%25 = load i32, i32* %7
%26 = icmp ult i32 %25, 32
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp ugt i32 %28, 37
br i1 %29, label %30, label %37
30: ; preds = %27, %24
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %27, %13
%38 = load i32, i32* %8
%39 = icmp ugt i32 %38, 1
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %37
%48 = call i32 @iopl(i32 3)
%49 = call i32 @inl(i32 62484)
store i32 %49, i32* %6
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = load i32, i32* %7
%57 = sub i32 %56, 32
%58 = shl i32 1, %57
%59 = or i32 %55, %58
store i32 %59, i32* %6
br label %69
60: ; preds = %47
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = sub i32 %64, 32
%66 = shl i32 1, %65
%67 = xor i32 %66, -1
%68 = and i32 %63, %67
store i32 %68, i32* %6
br label %69
69: ; preds = %60, %52
%70 = load i32, i32* %6
%71 = call i32 @outl(i32 %70, i32 62480)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Error: invalid GPIO port (%s)\0A\00"
@.str.1 = [31 x i8] c"Error: VAL not in {0,1}: (%s)\0A\00"
@.str.2 = [4 x i8] c"on\0A\00"
@.str.3 = [5 x i8] c"off\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
switch i32 %9, label %13 [
i32 39, label %17
i32 37, label %17
i32 36, label %17
i32 35, label %17
i32 34, label %17
i32 33, label %17
i32 32, label %17
]
13: ; preds = %6
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %6, %6, %6, %6, %6, %6, %6
%18 = icmp ugt i32 %12, 1
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%22 = tail call i32 @exit(i32 0)
unreachable
23: ; preds = %17
%24 = tail call i32 @iopl(i32 3)
%25 = tail call i32 @inl(i32 62484)
%26 = icmp eq i32 %12, 0
%27 = load i32, i32* @stderr
br i1 %26, label %33, label %28
28: ; preds = %23
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = add nsw i32 %9, -32
%31 = shl nuw nsw i32 1, %30
%32 = or i32 %25, %31
br label %39
33: ; preds = %23
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = add nsw i32 %9, -32
%36 = shl nuw nsw i32 1, %35
%37 = xor i32 %36, -1
%38 = and i32 %25, %37
br label %39
39: ; preds = %33, %28
%40 = phi i32 [ %32, %28 ], [ %38, %33 ]
%41 = tail call i32 @outl(i32 %40, i32 62480)
ret i32 0
}