#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 ENODEV;
int gpio_get_value(unsigned int const);
int /*<<< orphan*/ gpio_is_valid_port(unsigned int const);
int __p2ioport_get_gpio(const unsigned int gpio, int *const p_val) {
  int retval = 0;
  if (!gpio_is_valid_port(gpio)) {
    retval = -ENODEV;
    goto fail;
  }
  retval = gpio_get_value(gpio);
  if (retval < 0)
    goto fail;
  *p_val = retval ? 1 : 0;
fail:
  return retval;
}


x86 assembly (clang, -O0):
<__p2ioport_get_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <gpio_is_valid_port@plt>
cmp    $0x0,%eax
jne    115a <__p2ioport_get_gpio+0x3a>
xor    %eax,%eax
mov    0x2e90(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
jmp    118a <__p2ioport_get_gpio+0x6a>
mov    -0x4(%rbp),%edi
call   1040 <gpio_get_value@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1174 <__p2ioport_get_gpio+0x54>
jmp    118a <__p2ioport_get_gpio+0x6a>
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__p2ioport_get_gpio>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <gpio_is_valid_port@plt>
test   %eax,%eax
je     1146 <__p2ioport_get_gpio+0x26>
mov    %ebp,%edi
call   1040 <gpio_get_value@plt>
test   %eax,%eax
js     1151 <__p2ioport_get_gpio+0x31>
setne  %cl
movzbl %cl,%ecx
mov    %ecx,(%rbx)
jmp    1151 <__p2ioport_get_gpio+0x31>
mov    0x2e93(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@ENODEV = global i32 0
define i32 @__p2ioport_get_gpio(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = call i32 @gpio_is_valid_port(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @ENODEV
%11 = sub nsw i32 0, %10
store i32 %11, i32* %5
br label %24
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i32 @gpio_get_value(i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %24
18: ; preds = %12
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 0
%23 = load i32*, i32** %4
store i32 %22, i32* %23
br label %24
24: ; preds = %18, %17, %9
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@ENODEV = global i32 0
define i32 @__p2ioport_get_gpio(i32 %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @gpio_is_valid_port(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @ENODEV
%7 = sub nsw i32 0, %6
br label %14
8: ; preds = %2
%9 = tail call i32 @gpio_get_value(i32 %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = icmp ne i32 %9, 0
%13 = zext i1 %12 to i32
store i32 %13, i32* %1
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ %9, %8 ], [ %9, %11 ], [ %7, %5 ]
ret i32 %15
}