#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 lookup_gpio_by_altname(char const *);
int lookup_gpio_by_key(char const *);
int lookup_gpio_by_name(char const *);
int lookup_gpio_by_number(char const *);
int get_gpio_number(const char *key, int *gpio) {
  int status = 0;
  *gpio = lookup_gpio_by_key(key);
  if (*gpio <= 0) {
    *gpio = lookup_gpio_by_name(key);
    if (*gpio <= 0) {
      *gpio = lookup_gpio_by_altname(key);
      if (*gpio <= 0) {
        *gpio = lookup_gpio_by_number(key);
        if (*gpio <= 0) {
          status = -1;
        }
      }
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<get_gpio_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <lookup_gpio_by_key@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11e5 <get_gpio_number+0xa5>
mov    -0x8(%rbp),%rdi
call   1040 <lookup_gpio_by_name@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11e0 <get_gpio_number+0xa0>
mov    -0x8(%rbp),%rdi
call   1060 <lookup_gpio_by_altname@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11db <get_gpio_number+0x9b>
mov    -0x8(%rbp),%rdi
call   1030 <lookup_gpio_by_number@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11d6 <get_gpio_number+0x96>
movl   $0xffffffff,-0x14(%rbp)
jmp    11db <get_gpio_number+0x9b>
jmp    11e0 <get_gpio_number+0xa0>
jmp    11e5 <get_gpio_number+0xa5>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gpio_number>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1050 <lookup_gpio_by_key@plt>
mov    %eax,(%rbx)
xor    %r14d,%r14d
test   %eax,%eax
jg     118a <get_gpio_number+0x4a>
mov    %rbp,%rdi
call   1040 <lookup_gpio_by_name@plt>
mov    %eax,(%rbx)
test   %eax,%eax
jg     118a <get_gpio_number+0x4a>
mov    %rbp,%rdi
call   1060 <lookup_gpio_by_altname@plt>
mov    %eax,(%rbx)
test   %eax,%eax
jg     118a <get_gpio_number+0x4a>
mov    %rbp,%rdi
call   1030 <lookup_gpio_by_number@plt>
mov    %eax,(%rbx)
xor    %r14d,%r14d
test   %eax,%eax
setle  %r14b
neg    %r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_gpio_number(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = call i32 @lookup_gpio_by_key(i8* %6)
%8 = load i32*, i32** %4
store i32 %7, i32* %8
%9 = load i32*, i32** %4
%10 = load i32, i32* %9
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @lookup_gpio_by_name(i8* %13)
%15 = load i32*, i32** %4
store i32 %14, i32* %15
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i32 @lookup_gpio_by_altname(i8* %20)
%22 = load i32*, i32** %4
store i32 %21, i32* %22
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %19
%27 = load i8*, i8** %3
%28 = call i32 @lookup_gpio_by_number(i8* %27)
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = icmp sle i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 -1, i32* %5
br label %34
34: ; preds = %33, %26
br label %35
35: ; preds = %34, %19
br label %36
36: ; preds = %35, %12
br label %37
37: ; preds = %36, %2
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @get_gpio_number(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @lookup_gpio_by_key(i8* %0)
store i32 %3, i32* %1
%4 = icmp slt i32 %3, 1
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = tail call i32 @lookup_gpio_by_name(i8* %0)
store i32 %6, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = tail call i32 @lookup_gpio_by_altname(i8* %0)
store i32 %9, i32* %1
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = tail call i32 @lookup_gpio_by_number(i8* %0)
store i32 %12, i32* %1
%13 = icmp slt i32 %12, 1
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %11, %5, %8, %2
%16 = phi i32 [ 0, %8 ], [ 0, %5 ], [ 0, %2 ], [ %14, %11 ]
ret i32 %16
}