#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_sysfs_node_exists(uint32_t sysfsid) {
  struct stat fileStat;
  int result;
  switch (sysfsid) {
  case 2:
    result = stat("/sys/class/pwm/pwmchip0/pwm0", &fileStat);
    break;
  case 3:
    result = stat("/sys/class/pwm/pwmchip0/pwm1", &fileStat);
    break;
  default:
    result = -1;
  }
  return result < 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<librpip_sysfs_node_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x2,%eax
je     1140 <librpip_sysfs_node_exists+0x30>
jmp    112f <librpip_sysfs_node_exists+0x1f>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     1158 <librpip_sysfs_node_exists+0x48>
jmp    1170 <librpip_sysfs_node_exists+0x60>
lea    0xeb9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    1177 <librpip_sysfs_node_exists+0x67>
lea    0xebe(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
jmp    1177 <librpip_sysfs_node_exists+0x67>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_sysfs_node_exists>:
cmp    $0x2,%edi
je     1125 <librpip_sysfs_node_exists+0x15>
xor    %eax,%eax
cmp    $0x3,%edi
jne    113e <librpip_sysfs_node_exists+0x2e>
lea    0xefa(%rip),%rdi
jmp    112c <librpip_sysfs_node_exists+0x1c>
lea    0xed4(%rip),%rdi
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
not    %eax
shr    $0x1f,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [29 x i8] c"/sys/class/pwm/pwmchip0/pwm0\00"
@.str.1 = [29 x i8] c"/sys/class/pwm/pwmchip0/pwm1\00"
define i32 @librpip_sysfs_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 %10 [
i32 2, label %6
i32 3, label %8
]
6: ; preds = %1
%7 = call i32 @stat(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
store i32 %7, i32* %4
br label %11
8: ; preds = %1
%9 = call i32 @stat(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %3)
store i32 %9, i32* %4
br label %11
10: ; preds = %1
store i32 -1, i32* %4
br label %11
11: ; preds = %10, %8, %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 0, i32 1
ret i32 %15
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [29 x i8] c"/sys/class/pwm/pwmchip0/pwm0\00"
@.str.1 = [29 x i8] c"/sys/class/pwm/pwmchip0/pwm1\00"
define i32 @librpip_sysfs_node_exists(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
switch i32 %0, label %10 [
i32 2, label %5
i32 3, label %4
]
4: ; preds = %1
br label %5
5: ; preds = %1, %4
%6 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %1 ]
%7 = call i32 @stat(i8* %6, %struct.stat* %2)
%8 = xor i32 %7, -1
%9 = lshr i32 %8, 31
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ 0, %1 ], [ %9, %5 ]
ret i32 %11
}