#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ librpip_sysfs_node_file_open(int, int, int /*<<< orphan*/,
                                                int *);
uint32_t librpip_sysfs_node_file_validate(uint32_t sysfsid) {
  int fd1, fd2, fd3, fd4;
  uint32_t result;
  result = 0;
  switch (sysfsid) {
  case 2:
  case 3:
    if (librpip_sysfs_node_file_open(sysfsid, 1, O_RDWR, &fd1) &&
        librpip_sysfs_node_file_open(sysfsid, 2, O_RDWR, &fd2) &&
        librpip_sysfs_node_file_open(sysfsid, 3, O_RDWR, &fd3) &&
        librpip_sysfs_node_file_open(sysfsid, 4, O_RDWR, &fd4)) {
      result = 1;
    }
    if (fd1 > 0)
      close(fd1);
    if (fd2 > 0)
      close(fd2);
    if (fd3 > 0)
      close(fd3);
    if (fd4 > 0)
      close(fd4);
    break;
  }
  return result;
}


x86 assembly (clang, -O0):
<librpip_sysfs_node_file_validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x1,%eax
ja     1226 <librpip_sysfs_node_file_validate+0x106>
jmp    1146 <librpip_sysfs_node_file_validate+0x26>
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
lea    -0x8(%rbp),%rcx
call   1040 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%eax
je     11d9 <librpip_sysfs_node_file_validate+0xb9>
mov    -0x4(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
lea    -0xc(%rbp),%rcx
call   1040 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%eax
je     11d9 <librpip_sysfs_node_file_validate+0xb9>
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
lea    -0x10(%rbp),%rcx
call   1040 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%eax
je     11d9 <librpip_sysfs_node_file_validate+0xb9>
mov    -0x4(%rbp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
lea    -0x14(%rbp),%rcx
call   1040 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%eax
je     11d9 <librpip_sysfs_node_file_validate+0xb9>
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11eb <librpip_sysfs_node_file_validate+0xcb>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11fd <librpip_sysfs_node_file_validate+0xdd>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x10(%rbp)
jle    120f <librpip_sysfs_node_file_validate+0xef>
mov    -0x10(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1221 <librpip_sysfs_node_file_validate+0x101>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
jmp    1226 <librpip_sysfs_node_file_validate+0x106>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_sysfs_node_file_validate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
and    $0xfffffffe,%eax
xor    %ebx,%ebx
cmp    $0x2,%eax
jne    11d5 <librpip_sysfs_node_file_validate+0xb5>
mov    %edi,%ebp
mov    0x2ea7(%rip),%r14
mov    (%r14),%edx
lea    0xc(%rsp),%rcx
mov    $0x1,%esi
call   1040 <librpip_sysfs_node_file_open@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     11a2 <librpip_sysfs_node_file_validate+0x82>
mov    (%r14),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <librpip_sysfs_node_file_open@plt>
test   %eax,%eax
je     11a2 <librpip_sysfs_node_file_validate+0x82>
mov    (%r14),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x3,%esi
call   1040 <librpip_sysfs_node_file_open@plt>
test   %eax,%eax
je     11a2 <librpip_sysfs_node_file_validate+0x82>
mov    (%r14),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x4,%esi
call   1040 <librpip_sysfs_node_file_open@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11af <librpip_sysfs_node_file_validate+0x8f>
call   1030 <close@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
jle    11bc <librpip_sysfs_node_file_validate+0x9c>
call   1030 <close@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11c9 <librpip_sysfs_node_file_validate+0xa9>
call   1030 <close@plt>
mov    (%rsp),%edi
test   %edi,%edi
jle    11d5 <librpip_sysfs_node_file_validate+0xb5>
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
define i32 @librpip_sysfs_node_file_validate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %7
%8 = load i32, i32* %2
switch i32 %8, label %55 [
i32 2, label %9
i32 3, label %9
]
9: ; preds = %1, %1
%10 = load i32, i32* %2
%11 = load i32, i32* @O_RDWR
%12 = call i32 @librpip_sysfs_node_file_open(i32 %10, i32 1, i32 %11, i32* %3)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* @O_RDWR
%17 = call i32 @librpip_sysfs_node_file_open(i32 %15, i32 2, i32 %16, i32* %4)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32, i32* %2
%21 = load i32, i32* @O_RDWR
%22 = call i32 @librpip_sysfs_node_file_open(i32 %20, i32 3, i32 %21, i32* %5)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* %2
%26 = load i32, i32* @O_RDWR
%27 = call i32 @librpip_sysfs_node_file_open(i32 %25, i32 4, i32 %26, i32* %6)
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %7
br label %30
30: ; preds = %29, %24, %19, %14, %9
%31 = load i32, i32* %3
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %4
%41 = call i32 @close(i32 %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* %5
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %5
%47 = call i32 @close(i32 %46)
br label %48
48: ; preds = %45, %42
%49 = load i32, i32* %6
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
br label %54
54: ; preds = %51, %48
br label %55
55: ; preds = %1, %54
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @librpip_sysfs_node_file_validate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = and i32 %0, -2
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %50
12: ; preds = %1
%13 = load i32, i32* @O_RDWR
%14 = call i32 @librpip_sysfs_node_file_open(i32 %0, i32 1, i32 %13, i32* %2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %29, label %16
16: ; preds = %12
%17 = load i32, i32* @O_RDWR
%18 = call i32 @librpip_sysfs_node_file_open(i32 %0, i32 2, i32 %17, i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = load i32, i32* @O_RDWR
%22 = call i32 @librpip_sysfs_node_file_open(i32 %0, i32 3, i32 %21, i32* %4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i32, i32* @O_RDWR
%26 = call i32 @librpip_sysfs_node_file_open(i32 %0, i32 4, i32 %25, i32* %5)
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %24, %20, %16, %12
%30 = phi i32 [ 0, %20 ], [ 0, %16 ], [ 0, %12 ], [ %28, %24 ]
%31 = load i32, i32* %2
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @close(i32 %31)
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @close(i32 %36)
br label %40
40: ; preds = %38, %35
%41 = load i32, i32* %4
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @close(i32 %41)
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* %5
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @close(i32 %46)
br label %50
50: ; preds = %1, %45, %48
%51 = phi i32 [ 0, %1 ], [ %30, %48 ], [ %30, %45 ]
ret i32 %51
}