#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 /*<<< orphan*/ dir_name;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ sys_read_uint(char *, char *, unsigned int *);
unsigned is_ib_type(char *ca_name) {
  char dir_name[256];
  unsigned type;
  snprintf(dir_name, sizeof(dir_name), "%s/%s", "/sys/class/infiniband",
           ca_name);
  if (sys_read_uint(dir_name, "node_type", &type) < 0)
    return 0;
  return type >= 1 && type <= 3 ? 1 : 0;
}


x86 assembly (clang, -O0):
<is_ib_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xeba(%rip),%rdx
lea    0xeb9(%rip),%rcx
call   1030 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xebc(%rip),%rsi
lea    -0x114(%rbp),%rdx
call   1040 <sys_read_uint@plt>
cmp    $0x0,%rax
jge    1182 <is_ib_type+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11bd <is_ib_type+0x9d>
xor    %eax,%eax
cmpl   $0x1,-0x114(%rbp)
mov    %al,-0x115(%rbp)
jb     11a7 <is_ib_type+0x87>
cmpl   $0x3,-0x114(%rbp)
setbe  %al
mov    %al,-0x115(%rbp)
mov    -0x115(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ib_type>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%r8
lea    0xece(%rip),%rdx
lea    0xecd(%rip),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
lea    0xeca(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sys_read_uint@plt>
test   %rax,%rax
setns  %al
mov    0xc(%rsp),%ecx
add    $0xffffffff,%ecx
cmp    $0x3,%ecx
setb   %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [22 x i8] c"/sys/class/infiniband\00"
@.str.2 = [10 x i8] c"node_type\00"
define i32 @is_ib_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = call i64 @sys_read_uint(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %23
13: ; preds = %1
%14 = load i32, i32* %5
%15 = icmp uge i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %5
%18 = icmp ule i32 %17, 3
br label %19
19: ; preds = %16, %13
%20 = phi i1 [ false, %13 ], [ %18, %16 ]
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 1, i32 0
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %12
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [22 x i8] c"/sys/class/infiniband\00"
@.str.2 = [10 x i8] c"node_type\00"
define i32 @is_ib_type(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = call i64 @sys_read_uint(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%8 = icmp sgt i64 %7, -1
%9 = load i32, i32* %3
%10 = add i32 %9, -1
%11 = icmp ult i32 %10, 3
%12 = select i1 %8, i1 %11, i1 false
%13 = zext i1 %12 to i32
ret i32 %13
}