#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_dt_module_exists(uint32_t moduleid) {
  struct stat fileStat;
  int result;
  switch (moduleid) {
  case 1:
    result = stat("/sys/firmware/devicetree/base/soc/gpiomem", &fileStat);
    break;
  case 2:
    result = stat("/sys/firmware/devicetree/base/soc/gpio@7e200000", &fileStat);
    break;
  case 3:
    result = stat("/sys/firmware/devicetree/base/soc/i2c@7e205000", &fileStat);
    break;
  case 4:
    result = stat("/sys/firmware/devicetree/base/soc/i2c@7e804000", &fileStat);
    break;
  case 5:
    result = stat("/sys/firmware/devicetree/base/soc/i2s@7e203000", &fileStat);
    break;
  case 6:
    result = stat("/sys/firmware/devicetree/base/soc/pwm@7e20c000", &fileStat);
    break;
  case 7:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e204000", &fileStat);
    break;
  case 8:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@0",
                  &fileStat);
    break;
  case 9:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@1",
                  &fileStat);
    break;
  case 10:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e215080", &fileStat);
    break;
  case 11:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@0",
                  &fileStat);
    break;
  case 12:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@1",
                  &fileStat);
    break;
  case 13:
    result = stat("/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@2",
                  &fileStat);
    break;
  case 14:
    result = stat("/sys/firmware/devicetree/base/soc/uart@7e201000", &fileStat);
    break;
  case 15:
    result = stat("/sys/firmware/devicetree/base/soc/uart@7e215040", &fileStat);
    break;
  case 16:
    result = stat("/sys/firmware/devicetree/base/onewire@0", &fileStat);
    break;
  default:
    result = -1;
  }
  return result < 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<librpip_dt_module_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    $0xf,%eax
ja     12c4 <librpip_dt_module_exists+0x1b4>
mov    -0x18(%rbp),%rax
lea    0xec5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf07(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf1f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf36(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf4d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf64(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf7b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xf92(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xfb2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xfd2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0xfe9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0x1009(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0x1029(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0x1049(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0x1061(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
lea    0x1079(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    12cb <librpip_dt_module_exists+0x1bb>
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_dt_module_exists>:
add    $0xffffffff,%edi
xor    %eax,%eax
cmp    $0xf,%edi
ja     113d <librpip_dt_module_exists+0x2d>
push   %rax
movslq %edi,%rax
lea    0x11ef(%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 = [42 x i8] c"/sys/firmware/devicetree/base/soc/gpiomem\00"
@.str.1 = [48 x i8] c"/sys/firmware/devicetree/base/soc/gpio@7e200000\00"
@.str.2 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2c@7e205000\00"
@.str.3 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2c@7e804000\00"
@.str.4 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2s@7e203000\00"
@.str.5 = [47 x i8] c"/sys/firmware/devicetree/base/soc/pwm@7e20c000\00"
@.str.6 = [47 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000\00"
@.str.7 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@0\00"
@.str.8 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@1\00"
@.str.9 = [47 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080\00"
@.str.10 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@0\00"
@.str.11 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@1\00"
@.str.12 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@2\00"
@.str.13 = [48 x i8] c"/sys/firmware/devicetree/base/soc/uart@7e201000\00"
@.str.14 = [48 x i8] c"/sys/firmware/devicetree/base/soc/uart@7e215040\00"
@.str.15 = [40 x i8] c"/sys/firmware/devicetree/base/onewire@0\00"
define i32 @librpip_dt_module_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 %38 [
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
i32 11, label %26
i32 12, label %28
i32 13, label %30
i32 14, label %32
i32 15, label %34
i32 16, label %36
]
6: ; preds = %1
%7 = call i32 @stat(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
store i32 %7, i32* %4
br label %39
8: ; preds = %1
%9 = call i32 @stat(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %3)
store i32 %9, i32* %4
br label %39
10: ; preds = %1
%11 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %3)
store i32 %11, i32* %4
br label %39
12: ; preds = %1
%13 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %3)
store i32 %13, i32* %4
br label %39
14: ; preds = %1
%15 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %3)
store i32 %15, i32* %4
br label %39
16: ; preds = %1
%17 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), %struct.stat* %3)
store i32 %17, i32* %4
br label %39
18: ; preds = %1
%19 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), %struct.stat* %3)
store i32 %19, i32* %4
br label %39
20: ; preds = %1
%21 = call i32 @stat(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %3)
store i32 %21, i32* %4
br label %39
22: ; preds = %1
%23 = call i32 @stat(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), %struct.stat* %3)
store i32 %23, i32* %4
br label %39
24: ; preds = %1
%25 = call i32 @stat(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0), %struct.stat* %3)
store i32 %25, i32* %4
br label %39
26: ; preds = %1
%27 = call i32 @stat(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i64 0, i64 0), %struct.stat* %3)
store i32 %27, i32* %4
br label %39
28: ; preds = %1
%29 = call i32 @stat(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.11, i64 0, i64 0), %struct.stat* %3)
store i32 %29, i32* %4
br label %39
30: ; preds = %1
%31 = call i32 @stat(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.12, i64 0, i64 0), %struct.stat* %3)
store i32 %31, i32* %4
br label %39
32: ; preds = %1
%33 = call i32 @stat(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0), %struct.stat* %3)
store i32 %33, i32* %4
br label %39
34: ; preds = %1
%35 = call i32 @stat(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.14, i64 0, i64 0), %struct.stat* %3)
store i32 %35, i32* %4
br label %39
36: ; preds = %1
%37 = call i32 @stat(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0), %struct.stat* %3)
store i32 %37, i32* %4
br label %39
38: ; preds = %1
store i32 -1, i32* %4
br label %39
39: ; preds = %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 0, i32 1
ret i32 %43
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [42 x i8] c"/sys/firmware/devicetree/base/soc/gpiomem\00"
@.str.1 = [48 x i8] c"/sys/firmware/devicetree/base/soc/gpio@7e200000\00"
@.str.2 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2c@7e205000\00"
@.str.3 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2c@7e804000\00"
@.str.4 = [47 x i8] c"/sys/firmware/devicetree/base/soc/i2s@7e203000\00"
@.str.5 = [47 x i8] c"/sys/firmware/devicetree/base/soc/pwm@7e20c000\00"
@.str.6 = [47 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000\00"
@.str.7 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@0\00"
@.str.8 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e204000/spidev@1\00"
@.str.9 = [47 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080\00"
@.str.10 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@0\00"
@.str.11 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@1\00"
@.str.12 = [56 x i8] c"/sys/firmware/devicetree/base/soc/spi@7e215080/spidev@2\00"
@.str.13 = [48 x i8] c"/sys/firmware/devicetree/base/soc/uart@7e201000\00"
@.str.14 = [48 x i8] c"/sys/firmware/devicetree/base/soc/uart@7e215040\00"
@.str.15 = [40 x i8] c"/sys/firmware/devicetree/base/onewire@0\00"
@reltable.librpip_dt_module_exists = [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([42 x i8]* @.str to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([48 x i8]* @.str.1 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.2 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.3 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.4 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.5 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.6 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.7 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.8 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([47 x i8]* @.str.9 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.10 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.11 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.12 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([48 x i8]* @.str.13 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([48 x i8]* @.str.14 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([40 x i8]* @.str.15 to i64), i64 ptrtoint ([16 x i32]* @reltable.librpip_dt_module_exists to i64)) to i32)]
define i32 @librpip_dt_module_exists(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = add i32 %0, -1
%5 = icmp ult i32 %4, 16
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 ([16 x i32]* @reltable.librpip_dt_module_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
}