#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_pud_capable_by_altname(char const *);
int lookup_pud_capable_by_key(char const *);
int lookup_pud_capable_by_name(char const *);
int compute_port_pin(const char *key, int gpio, int *port, int *pin) {
  int capable = 0;
  int rtn = -1;
  capable = lookup_pud_capable_by_key(key);
  if (capable < 0) {
    capable = lookup_pud_capable_by_name(key);
    if (capable < 0) {
      capable = lookup_pud_capable_by_altname(key);
      if (capable < 0) {
        capable = 0;
      }
    }
  }
  if (capable) {
    *port = gpio / 32;
    *pin = gpio % 32;
    rtn = 0;
  }
  return rtn;
}


x86 assembly (clang, -O0):
<compute_port_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <lookup_pud_capable_by_key@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a8 <compute_port_pin+0x78>
mov    -0x8(%rbp),%rdi
call   1050 <lookup_pud_capable_by_name@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a3 <compute_port_pin+0x73>
mov    -0x8(%rbp),%rdi
call   1030 <lookup_pud_capable_by_altname@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    119e <compute_port_pin+0x6e>
movl   $0x0,-0x24(%rbp)
jmp    11a3 <compute_port_pin+0x73>
jmp    11a8 <compute_port_pin+0x78>
cmpl   $0x0,-0x24(%rbp)
je     11dd <compute_port_pin+0xad>
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
mov    %edx,(%rax)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_port_pin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r12
call   1040 <lookup_pud_capable_by_key@plt>
test   %eax,%eax
jns    1158 <compute_port_pin+0x28>
mov    %r12,%rdi
call   1050 <lookup_pud_capable_by_name@plt>
test   %eax,%eax
js     1178 <compute_port_pin+0x48>
test   %eax,%eax
je     1184 <compute_port_pin+0x54>
lea    0x1f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
mov    %eax,%ecx
sar    $0x5,%ecx
mov    %ecx,(%r15)
and    $0xffffffe0,%eax
sub    %eax,%ebx
mov    %ebx,(%r14)
xor    %eax,%eax
jmp    1189 <compute_port_pin+0x59>
mov    %r12,%rdi
call   1030 <lookup_pud_capable_by_altname@plt>
test   %eax,%eax
jg     115c <compute_port_pin+0x2c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @compute_port_pin(i8* %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @lookup_pud_capable_by_key(i8* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i32 @lookup_pud_capable_by_name(i8* %0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @lookup_pud_capable_by_altname(i8* %0)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %16, label %19
13: ; preds = %7, %4
%14 = phi i32 [ %8, %7 ], [ %5, %4 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10, %13
%17 = sdiv i32 %1, 32
store i32 %17, i32* %2
%18 = srem i32 %1, 32
store i32 %18, i32* %3
br label %19
19: ; preds = %10, %16, %13
%20 = phi i32 [ 0, %16 ], [ -1, %13 ], [ -1, %10 ]
ret i32 %20
}