#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;
struct stat {
  int dummy;
};

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


x86 assembly (clang, -O0):
<librpip_device_node_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x9,%eax
ja     1234 <librpip_device_node_exists+0x124>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xedd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xead(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xea0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xe97(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xe8e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xe85(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
lea    0xe6d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    123b <librpip_device_node_exists+0x12b>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%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_exists>:
add    $0xffffffff,%edi
xor    %eax,%eax
cmp    $0x9,%edi
ja     113d <librpip_device_node_exists+0x2d>
push   %rax
movslq %edi,%rax
lea    0xf53(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
mov    %rsp,%rsi
call   1030 <stat@plt>
not    %eax
shr    $0x1f,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.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"
define i32 @librpip_device_node_exists(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
switch i32 %5, label %26 [
i32 1, label %6
i32 2, label %8
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 6, label %16
i32 7, label %18
i32 8, label %20
i32 9, label %22
i32 10, label %24
]
6: ; preds = %1
%7 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
store i32 %7, i32* %4
br label %27
8: ; preds = %1
%9 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %3)
store i32 %9, i32* %4
br label %27
10: ; preds = %1
%11 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %3)
store i32 %11, i32* %4
br label %27
12: ; preds = %1
%13 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %3)
store i32 %13, i32* %4
br label %27
14: ; preds = %1
%15 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %3)
store i32 %15, i32* %4
br label %27
16: ; preds = %1
%17 = call i32 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %3)
store i32 %17, i32* %4
br label %27
18: ; preds = %1
%19 = call i32 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), %struct.stat* %3)
store i32 %19, i32* %4
br label %27
20: ; preds = %1
%21 = call i32 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %3)
store i32 %21, i32* %4
br label %27
22: ; preds = %1
%23 = call i32 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %struct.stat* %3)
store i32 %23, i32* %4
br label %27
24: ; preds = %1
%25 = call i32 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), %struct.stat* %3)
store i32 %25, i32* %4
br label %27
26: ; preds = %1
store i32 -1, i32* %4
br label %27
27: ; preds = %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 0, i32 1
ret i32 %31
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.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"
@reltable.librpip_device_node_exists = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.librpip_device_node_exists 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_exists 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_exists 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_exists 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_exists 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_exists 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_exists 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_exists 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_exists 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_exists to i64)) to i32)]
define i32 @librpip_device_node_exists(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = add i32 %0, -1
%5 = icmp ult i32 %4, 10
br i1 %5, label %6, label %13
6: ; preds = %1
%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_exists to i8*), i64 %8)
%10 = call i32 @stat(i8* %9, %struct.stat* %2)
%11 = xor i32 %10, -1
%12 = lshr i32 %11, 31
br label %13
13: ; preds = %1, %6
%14 = phi i32 [ 0, %1 ], [ %12, %6 ]
ret i32 %14
}