#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *memmem(char *, int, char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
scalar_t__ stat(char *, struct stat *);
int init_temp(int *fds, int fds_len) {
  char buf[256] = {0};
  char buf_file[256] = {0};
  int i, j;
  int fd;
  int ret;
  struct stat sb;
  int fd_ptr = 0;
  if (fds_len == 0) {
    return 0;
  }
  for (i = 0; i < 32; i += 1) {
    snprintf(buf, 256, "/sys/class/hwmon/hwmon%d", i);
    if (stat(buf, &sb) != 0 || !S_ISDIR(sb.st_mode)) {
      continue;
    }
    for (j = 0; j < 32; j += 1) {
      snprintf(buf, 256, "/sys/class/hwmon/hwmon%d/temp%d_label", i, j);
      fd = open(buf, O_RDONLY);
      if (fd == -1) {
        continue;
      }
      ret = read(fd, buf_file, 256);
      if (ret == -1) {
        continue;
      }
      close(fd);
      if (memmem(buf_file, ret, "Package", 7) == NULL &&
          memmem(buf_file, ret, "Core", 4) == NULL) {
        continue;
      }
      snprintf(buf, 256, "/sys/class/hwmon/hwmon%d/temp%d_input", i, j);
      fd = open(buf, O_RDONLY);
      if (fd == -1) {
        continue;
      }
      if (fd_ptr < fds_len) {
        fds[fd_ptr] = fd;
        fd_ptr += 1;
      } else {
        return fd_ptr;
      }
    }
  }
  return fd_ptr;
}


x86 assembly (clang, -O0):
<init_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movl   $0x0,-0x23c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11d8 <init_temp+0x58>
movl   $0x0,-0x4(%rbp)
jmp    1413 <init_temp+0x293>
movl   $0x0,-0x224(%rbp)
cmpl   $0x20,-0x224(%rbp)
jge    140a <init_temp+0x28a>
lea    -0x120(%rbp),%rdi
mov    -0x224(%rbp),%ecx
mov    $0x100,%esi
lea    0xdf8(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x238(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jne    1240 <init_temp+0xc0>
mov    -0x238(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1245 <init_temp+0xc5>
jmp    13f6 <init_temp+0x276>
movl   $0x0,-0x228(%rbp)
cmpl   $0x20,-0x228(%rbp)
jge    13f1 <init_temp+0x271>
lea    -0x120(%rbp),%rdi
mov    -0x224(%rbp),%ecx
mov    -0x228(%rbp),%r8d
mov    $0x100,%esi
lea    0xd9d(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0xffffffff,-0x22c(%rbp)
jne    12b0 <init_temp+0x130>
jmp    13dd <init_temp+0x25d>
mov    -0x22c(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,-0x230(%rbp)
cmpl   $0xffffffff,-0x230(%rbp)
jne    12df <init_temp+0x15f>
jmp    13dd <init_temp+0x25d>
mov    -0x22c(%rbp),%edi
call   1060 <close@plt>
lea    -0x220(%rbp),%rdi
mov    -0x230(%rbp),%esi
lea    0xd41(%rip),%rdx
mov    $0x7,%ecx
call   1090 <memmem@plt>
cmp    $0x0,%rax
jne    133f <init_temp+0x1bf>
lea    -0x220(%rbp),%rdi
mov    -0x230(%rbp),%esi
lea    0xd21(%rip),%rdx
mov    $0x4,%ecx
call   1090 <memmem@plt>
cmp    $0x0,%rax
jne    133f <init_temp+0x1bf>
jmp    13dd <init_temp+0x25d>
lea    -0x120(%rbp),%rdi
mov    -0x224(%rbp),%ecx
mov    -0x228(%rbp),%r8d
mov    $0x100,%esi
lea    0xced(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2c74(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0xffffffff,-0x22c(%rbp)
jne    1393 <init_temp+0x213>
jmp    13dd <init_temp+0x25d>
mov    -0x23c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13ca <init_temp+0x24a>
mov    -0x22c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    13d8 <init_temp+0x258>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1413 <init_temp+0x293>
jmp    13dd <init_temp+0x25d>
mov    -0x228(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x228(%rbp)
jmp    124f <init_temp+0xcf>
jmp    13f6 <init_temp+0x276>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    11e2 <init_temp+0x62>
mov    -0x23c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_temp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,0x18(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %esi,0x14(%rsp)
test   %esi,%esi
je     1425 <init_temp+0x2b5>
lea    0x120(%rsp),%rbx
mov    0x2d56(%rip),%rbp
lea    0x20(%rsp),%r15
movl   $0x0,0x8(%rsp)
xor    %r13d,%r13d
jmp    12be <init_temp+0x14e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13d
cmp    $0x20,%r13d
je     142d <init_temp+0x2bd>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xd33(%rip),%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    12b0 <init_temp+0x140>
mov    0x10(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     12b0 <init_temp+0x140>
xor    %r14d,%r14d
mov    %r13d,0xc(%rsp)
jmp    131a <init_temp+0x1aa>
mov    %r12,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
cmp    $0x20,%r14d
je     12b0 <init_temp+0x140>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xcf0(%rip),%rdx
mov    %r13d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1310 <init_temp+0x1a0>
mov    %eax,%r12d
mov    %rbx,%r13
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %r15,%rbx
cmp    $0xffffffff,%eax
je     1410 <init_temp+0x2a0>
mov    %eax,%r15d
mov    %r12d,%edi
call   1050 <close@plt>
mov    %rbx,%r12
mov    %rbx,%rdi
mov    %r15d,%esi
lea    0xcbd(%rip),%rdx
mov    $0x7,%ecx
call   1080 <memmem@plt>
test   %rax,%rax
jne    13ad <init_temp+0x23d>
mov    %r12,%rdi
mov    %r15d,%esi
lea    0xca9(%rip),%rdx
mov    $0x4,%ecx
call   1080 <memmem@plt>
test   %rax,%rax
je     1420 <init_temp+0x2b0>
mov    %r13,%rbx
mov    %r13,%rdi
mov    $0x100,%esi
lea    0xc8d(%rip),%rdx
mov    0xc(%rsp),%r13d
mov    %r13d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1300 <init_temp+0x190>
mov    0x8(%rsp),%esi
cmp    0x14(%rsp),%esi
jge    142d <init_temp+0x2bd>
mov    %r12,%r15
movslq %esi,%rcx
mov    0x18(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
add    $0x1,%esi
mov    %esi,0x8(%rsp)
jmp    1310 <init_temp+0x1a0>
nopl   0x0(%rax)
mov    %rbx,%r15
mov    %r13,%rbx
mov    0xc(%rsp),%r13d
jmp    1310 <init_temp+0x1a0>
mov    %r12,%r15
jmp    1413 <init_temp+0x2a3>
movl   $0x0,0x8(%rsp)
mov    0x8(%rsp),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [25 x i8] c"/sys/class/hwmon/hwmon%d\00"
@.str.1 = [38 x i8] c"/sys/class/hwmon/hwmon%d/temp%d_label\00"
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"Package\00"
@.str.3 = [5 x i8] c"Core\00"
@.str.4 = [38 x i8] c"/sys/class/hwmon/hwmon%d/temp%d_input\00"
define i32 @init_temp(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.stat
%13 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%14 = bitcast [256 x i8]* %6 to i8*
%15 = bitcast [256 x i8]* %7 to i8*
store i32 0, i32* %13
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %3
br label %106
19: ; preds = %2
store i32 0, i32* %8
br label %20
20: ; preds = %101, %19
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 32
br i1 %22, label %23, label %104
23: ; preds = %20
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %8
%26 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %24, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i64 @stat(i8* %27, %struct.stat* %12)
%29 = icmp ne i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @S_ISDIR(i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %30, %23
br label %101
36: ; preds = %30
store i32 0, i32* %9
br label %37
37: ; preds = %97, %36
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 32
br i1 %39, label %40, label %100
40: ; preds = %37
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %41, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i8* %45, i32 %46)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %40
br label %97
51: ; preds = %40
%52 = load i32, i32* %10
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 256)
store i32 %54, i32* %11
%55 = load i32, i32* %11
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %58
57: ; preds = %51
br label %97
58: ; preds = %51
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%62 = load i32, i32* %11
%63 = call i32* @memmem(i8* %61, i32 %62, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%64 = icmp eq i32* %63, null
br i1 %64, label %65, label %71
65: ; preds = %58
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%67 = load i32, i32* %11
%68 = call i32* @memmem(i8* %66, i32 %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %71
70: ; preds = %65
br label %97
71: ; preds = %65, %58
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%73 = load i32, i32* %8
%74 = load i32, i32* %9
%75 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %72, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %73, i32 %74)
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%77 = load i32, i32* @O_RDONLY
%78 = call i32 @open(i8* %76, i32 %77)
store i32 %78, i32* %10
%79 = load i32, i32* %10
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %82
81: ; preds = %71
br label %97
82: ; preds = %71
%83 = load i32, i32* %13
%84 = load i32, i32* %5
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %94
86: ; preds = %82
%87 = load i32, i32* %10
%88 = load i32*, i32** %4
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
store i32 %87, i32* %91
%92 = load i32, i32* %13
%93 = add nsw i32 %92, 1
store i32 %93, i32* %13
br label %96
94: ; preds = %82
%95 = load i32, i32* %13
store i32 %95, i32* %3
br label %106
96: ; preds = %86
br label %97
97: ; preds = %96, %81, %70, %57, %50
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
store i32 %99, i32* %9
br label %37
100: ; preds = %37
br label %101
101: ; preds = %100, %35
%102 = load i32, i32* %8
%103 = add nsw i32 %102, 1
store i32 %103, i32* %8
br label %20
104: ; preds = %20
%105 = load i32, i32* %13
store i32 %105, i32* %3
br label %106
106: ; preds = %104, %94, %18
%107 = load i32, i32* %3
ret i32 %107
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [25 x i8] c"/sys/class/hwmon/hwmon%d\00"
@.str.1 = [38 x i8] c"/sys/class/hwmon/hwmon%d/temp%d_label\00"
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"Package\00"
@.str.3 = [5 x i8] c"Core\00"
@.str.4 = [38 x i8] c"/sys/class/hwmon/hwmon%d/temp%d_input\00"
define i32 @init_temp(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.stat* %5 to i8*
%9 = icmp eq i32 %1, 0
br i1 %9, label %58, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %12
12: ; preds = %10, %54
%13 = phi i32 [ 0, %10 ], [ %55, %54 ]
%14 = phi i32 [ 0, %10 ], [ %56, %54 ]
%15 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i64 @stat(i8* %6, %struct.stat* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %54
18: ; preds = %12
%19 = load i32, i32* %11
%20 = call i32 @S_ISDIR(i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %54, label %22
22: ; preds = %18, %50
%23 = phi i32 [ %51, %50 ], [ %13, %18 ]
%24 = phi i32 [ %52, %50 ], [ 0, %18 ]
%25 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %24)
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %6, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %50, label %29
29: ; preds = %22
%30 = call i32 @read(i32 %27, i8* %7, i32 256)
%31 = icmp eq i32 %30, -1
br i1 %31, label %50, label %32
32: ; preds = %29
%33 = call i32 @close(i32 %27)
%34 = call i32* @memmem(i8* %7, i32 %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32* @memmem(i8* %7, i32 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%38 = icmp eq i32* %37, null
br i1 %38, label %50, label %39
39: ; preds = %36, %32
%40 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %14, i32 %24)
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %6, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %50, label %44
44: ; preds = %39
%45 = icmp slt i32 %23, %1
br i1 %45, label %46, label %58
46: ; preds = %44
%47 = sext i32 %23 to i64
%48 = getelementptr inbounds i32, i32* %0, i64 %47
store i32 %42, i32* %48
%49 = add nsw i32 %23, 1
br label %50
50: ; preds = %39, %36, %29, %22, %46
%51 = phi i32 [ %23, %22 ], [ %23, %29 ], [ %23, %36 ], [ %23, %39 ], [ %49, %46 ]
%52 = add nuw nsw i32 %24, 1
%53 = icmp eq i32 %52, 32
br i1 %53, label %54, label %22
54: ; preds = %50, %12, %18
%55 = phi i32 [ %13, %12 ], [ %13, %18 ], [ %51, %50 ]
%56 = add nuw nsw i32 %14, 1
%57 = icmp eq i32 %56, 32
br i1 %57, label %58, label %12
58: ; preds = %54, %44, %2
%59 = phi i32 [ 0, %2 ], [ %23, %44 ], [ %55, %54 ]
ret i32 %59
}