#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 */
typedef int uint32_t;

/* Variables and functions */
int open(char *, int);
uint32_t librpip_device_node_open(uint32_t devid, int flags, int *dev) {
  switch (devid) {
  case 1:
    *dev = open("/dev/gpiomem", flags);
    break;
  case 2:
    *dev = open("/dev/ttyAMA0", flags);
    break;
  case 3:
    *dev = open("/dev/ttyS0", flags);
    break;
  case 4:
    *dev = open("/dev/i2c-0", flags);
    break;
  case 5:
    *dev = open("/dev/i2c-1", flags);
    break;
  case 6:
    *dev = open("/dev/spidev0.0", flags);
    break;
  case 7:
    *dev = open("/dev/spidev0.1", flags);
    break;
  case 8:
    *dev = open("/dev/spidev1.0", flags);
    break;
  case 9:
    *dev = open("/dev/spidev1.1", flags);
    break;
  case 10:
    *dev = open("/dev/spidev1.2", flags);
    break;
  default:
    *dev = -1;
  }
  return *dev < 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<librpip_device_node_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x9,%eax
ja     1263 <librpip_device_node_open+0x153>
mov    -0x18(%rbp),%rax
lea    0xebe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%esi
lea    0xed3(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xec4(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xeb5(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe5b(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x8(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1030 <open@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    126d <librpip_device_node_open+0x15d>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_device_node_open>:
push   %rbx
mov    %rdx,%rbx
add    $0xffffffff,%edi
mov    $0xffffffff,%eax
cmp    $0x9,%edi
ja     1137 <librpip_device_node_open+0x27>
movslq %edi,%rax
lea    0xf5d(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <open@plt>
mov    %eax,(%rbx)
not    %eax
shr    $0x1f,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/gpiomem\00"
@.str.1 = [13 x i8] c"/dev/ttyAMA0\00"
@.str.2 = [11 x i8] c"/dev/ttyS0\00"
@.str.3 = [11 x i8] c"/dev/i2c-0\00"
@.str.4 = [11 x i8] c"/dev/i2c-1\00"
@.str.5 = [15 x i8] c"/dev/spidev0.0\00"
@.str.6 = [15 x i8] c"/dev/spidev0.1\00"
@.str.7 = [15 x i8] c"/dev/spidev1.0\00"
@.str.8 = [15 x i8] c"/dev/spidev1.1\00"
@.str.9 = [15 x i8] c"/dev/spidev1.2\00"
define i32 @librpip_device_node_open(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %4
switch i32 %7, label %48 [
i32 1, label %8
i32 2, label %12
i32 3, label %16
i32 4, label %20
i32 5, label %24
i32 6, label %28
i32 7, label %32
i32 8, label %36
i32 9, label %40
i32 10, label %44
]
8: ; preds = %3
%9 = load i32, i32* %5
%10 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32*, i32** %6
store i32 %10, i32* %11
br label %50
12: ; preds = %3
%13 = load i32, i32* %5
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %6
store i32 %14, i32* %15
br label %50
16: ; preds = %3
%17 = load i32, i32* %5
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32*, i32** %6
store i32 %18, i32* %19
br label %50
20: ; preds = %3
%21 = load i32, i32* %5
%22 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %6
store i32 %22, i32* %23
br label %50
24: ; preds = %3
%25 = load i32, i32* %5
%26 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32*, i32** %6
store i32 %26, i32* %27
br label %50
28: ; preds = %3
%29 = load i32, i32* %5
%30 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %6
store i32 %30, i32* %31
br label %50
32: ; preds = %3
%33 = load i32, i32* %5
%34 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = load i32*, i32** %6
store i32 %34, i32* %35
br label %50
36: ; preds = %3
%37 = load i32, i32* %5
%38 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %6
store i32 %38, i32* %39
br label %50
40: ; preds = %3
%41 = load i32, i32* %5
%42 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %6
store i32 %42, i32* %43
br label %50
44: ; preds = %3
%45 = load i32, i32* %5
%46 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %6
store i32 %46, i32* %47
br label %50
48: ; preds = %3
%49 = load i32*, i32** %6
store i32 -1, i32* %49
br label %50
50: ; preds = %48, %44, %40, %36, %32, %28, %24, %20, %16, %12, %8
%51 = load i32*, i32** %6
%52 = load i32, i32* %51
%53 = icmp slt i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 0, i32 1
ret i32 %55
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/gpiomem\00"
@.str.1 = [13 x i8] c"/dev/ttyAMA0\00"
@.str.2 = [11 x i8] c"/dev/ttyS0\00"
@.str.3 = [11 x i8] c"/dev/i2c-0\00"
@.str.4 = [11 x i8] c"/dev/i2c-1\00"
@.str.5 = [15 x i8] c"/dev/spidev0.0\00"
@.str.6 = [15 x i8] c"/dev/spidev0.1\00"
@.str.7 = [15 x i8] c"/dev/spidev1.0\00"
@.str.8 = [15 x i8] c"/dev/spidev1.1\00"
@.str.9 = [15 x i8] c"/dev/spidev1.2\00"
@reltable.librpip_device_node_open = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_open to i64)) to i32)]
define i32 @librpip_device_node_open(i32 %0, i32 %1, i32* nocapture %2) {
%4 = add i32 %0, -1
%5 = icmp ult i32 %4, 10
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.librpip_device_node_open to i8*), i64 %8)
%10 = tail call i32 @open(i8* %9, i32 %1)
br label %11
11: ; preds = %3, %6
%12 = phi i32 [ -1, %3 ], [ %10, %6 ]
store i32 %12, i32* %2
%13 = xor i32 %12, -1
%14 = lshr i32 %13, 31
ret i32 %14
}