#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 *, char *);
unsigned int inl(int);
int /*<<< orphan*/ iopl(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int nargs, char **argv) {
  unsigned int val;
  unsigned int gpio;
  if (nargs != 2)
    usage();
  gpio = atoi(argv[1]);
  if ((gpio != 39) && (gpio < 32 || gpio > 37)) {
    fprintf(stderr, "Error: invalid GPIO port (%s)\n", argv[1]);
    exit(0);
  }
  iopl(3);
  val = inl(0xf400 + 0x14);
  val = val & (1 << (gpio - 32));
  printf("%c\n", (val != 0) ? '1' : '0');
  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     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)
cmpl   $0x27,-0x18(%rbp)
je     11e9 <main+0x79>
cmpl   $0x20,-0x18(%rbp)
jb     11c5 <main+0x55>
cmpl   $0x25,-0x18(%rbp)
jbe    11e9 <main+0x79>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x3,%edi
call   1040 <iopl@plt>
mov    $0xf414,%edi
call   1060 <inl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x20,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xdee(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1183 <main+0x13>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    -0x20(%rbx),%eax
cmp    $0x6,%eax
jae    11d4 <main+0x64>
mov    $0x3,%edi
call   1040 <iopl@plt>
mov    $0xf414,%edi
call   1060 <inl@plt>
add    $0xe0,%bl
movzbl %bl,%ecx
bt     %ecx,%eax
mov    $0x31,%esi
adc    $0xffffffff,%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
cmp    $0x27,%ebx
je     1199 <main+0x29>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    %r14,%rdx
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 = [4 x i8] c"%c\0A\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 (...) @usage()
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 39
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = load i32, i32* %7
%21 = icmp ult i32 %20, 32
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp ugt i32 %23, 37
br i1 %24, label %25, label %32
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %22, %12
%33 = call i32 @iopl(i32 3)
%34 = call i32 @inl(i32 62484)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = sub i32 %36, 32
%38 = shl i32 1, %37
%39 = and i32 %35, %38
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 49, i32 48
%44 = trunc i32 %43 to i8
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %44)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Error: invalid GPIO port (%s)\0A\00"
@.str.1 = [4 x i8] c"%c\0A\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 (...) @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)
switch i32 %9, label %10 [
i32 39, label %14
i32 37, label %14
i32 36, label %14
i32 35, label %14
i32 34, label %14
i32 33, label %14
i32 32, label %14
]
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %6, %6, %6, %6, %6, %6, %6
%15 = tail call i32 @iopl(i32 3)
%16 = tail call i32 @inl(i32 62484)
%17 = add nsw i32 %9, -32
%18 = shl nuw nsw i32 1, %17
%19 = and i32 %16, %18
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8 48, i8 49
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %21)
ret i32 0
}