#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*/ exit(int);
int inb(int);
int /*<<< orphan*/ ioperm(int, int, int);
scalar_t__ isNumber(char *);
int /*<<< orphan*/ printf(char *, ...);
int stringToInt(char *);
int doInb(int argc, char *argv[]) {
  if (argc == 2 && isNumber(argv[1])) {
    int puerto, valor;
    puerto = stringToInt(argv[1]);
    ioperm(puerto, 1, 1);
    valor = inb(puerto);
    ioperm(puerto, 1, 0);
    printf("0x%X\n", valor);
    return valor;
  }
  printf("modo de uso: inb <numero da porta>\n");
  exit(1);
}


x86 assembly (clang, -O0):
<doInb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    11e3 <doInb+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <isNumber@plt>
cmp    $0x0,%rax
je     11e3 <doInb+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <stringToInt@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <ioperm@plt>
mov    -0x14(%rbp),%edi
call   1060 <inb@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <ioperm@plt>
mov    -0x18(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<doInb>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11d5 <doInb+0x65>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <isNumber@plt>
test   %rax,%rax
je     11d5 <doInb+0x65>
mov    0x8(%rbx),%rdi
call   1080 <stringToInt@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
mov    %ebx,%edi
call   1070 <inb@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <ioperm@plt>
lea    0xe3d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"0x%X\0A\00"
@.str.1 = [36 x i8] c"modo de uso: inb <numero da porta>\0A\00"
define i32 @doInb(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %29
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @isNumber(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %9
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @stringToInt(i8* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i32 @ioperm(i32 %20, i32 1, i32 1)
%22 = load i32, i32* %5
%23 = call i32 @inb(i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = call i32 @ioperm(i32 %24, i32 1, i32 0)
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
ret i32 %28
29: ; preds = %9, %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"0x%X\0A\00"
@str = [35 x i8] c"modo de uso: inb <numero da porta>\00"
define i32 @doInb(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @isNumber(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i32 @stringToInt(i8* %10)
%12 = tail call i32 @ioperm(i32 %11, i32 1, i32 1)
%13 = tail call i32 @inb(i32 %11)
%14 = tail call i32 @ioperm(i32 %11, i32 1, i32 0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i32 %13
16: ; preds = %4, %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
}