#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logging_null(char *, float);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
char *sysfsparser_getline(char *, unsigned int, int);
int sysfsparser_getvalue(char *, unsigned int, int);
int sysfsparser_thermal_get_critical_temperature(unsigned int thermal_zone) {
  char *type;
  int i, crit_temp = -1;
  for (i = 0; i < 4; i++) {
    type = sysfsparser_getline("/sys/class"
                               "/thermal"
                               "/thermal_zone%u/trip_point_%d_type",
                               thermal_zone, i);
    if (NULL == type)
      continue;
    if (strncmp(type, "critical", strlen("critical")))
      continue;
    crit_temp = sysfsparser_getvalue("/sys/class"
                                     "/thermal"
                                     "/thermal_zone%u/trip_point_%d_temp",
                                     thermal_zone, i);
    if (crit_temp > 0)
      logging_null("a critical trip point has been found: %.2f degrees C\n",
                   (float)(crit_temp / 1000.0));
    free(type);
    break;
  }
  return crit_temp;
}


x86 assembly (clang, -O0):
<sysfsparser_thermal_get_critical_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    123b <sysfsparser_thermal_get_critical_temperature+0xdb>
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe78(%rip),%rdi
call   1070 <sysfsparser_getline@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11aa <sysfsparser_thermal_get_critical_temperature+0x4a>
jmp    122d <sysfsparser_thermal_get_critical_temperature+0xcd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe84(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe72(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11df <sysfsparser_thermal_get_critical_temperature+0x7f>
jmp    122d <sysfsparser_thermal_get_critical_temperature+0xcd>
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe5a(%rip),%rdi
call   1080 <sysfsparser_getvalue@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    121f <sysfsparser_thermal_get_critical_temperature+0xbf>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xdf5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe61(%rip),%rdi
call   1060 <logging_null@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    123b <sysfsparser_thermal_get_critical_temperature+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <sysfsparser_thermal_get_critical_temperature+0x19>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfsparser_thermal_get_critical_temperature>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
lea    0xe96(%rip),%rdi
xor    %r14d,%r14d
mov    %r15d,%esi
xor    %edx,%edx
call   1070 <sysfsparser_getline@plt>
test   %rax,%rax
je     11ac <sysfsparser_thermal_get_critical_temperature+0x4c>
mov    %rax,%rbp
lea    0xeaf(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     127e <sysfsparser_thermal_get_critical_temperature+0x11e>
lea    0xe55(%rip),%rdi
mov    $0x1,%r14d
mov    %r15d,%esi
mov    $0x1,%edx
call   1070 <sysfsparser_getline@plt>
test   %rax,%rax
je     11f3 <sysfsparser_thermal_get_critical_temperature+0x93>
mov    %rax,%rbp
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     127e <sysfsparser_thermal_get_critical_temperature+0x11e>
lea    0xe0e(%rip),%rdi
mov    $0x2,%r14d
mov    %r15d,%esi
mov    $0x2,%edx
call   1070 <sysfsparser_getline@plt>
test   %rax,%rax
je     1236 <sysfsparser_thermal_get_critical_temperature+0xd6>
mov    %rax,%rbp
lea    0xe21(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     127e <sysfsparser_thermal_get_critical_temperature+0x11e>
lea    0xdcb(%rip),%rdi
mov    $0x3,%r14d
mov    %r15d,%esi
mov    $0x3,%edx
call   1070 <sysfsparser_getline@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     12ba <sysfsparser_thermal_get_critical_temperature+0x15a>
mov    %rax,%rbp
lea    0xdd9(%rip),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    12ba <sysfsparser_thermal_get_critical_temperature+0x15a>
lea    0xdc1(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1080 <sysfsparser_getvalue@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    12b2 <sysfsparser_thermal_get_critical_temperature+0x152>
cvtsi2sd %ebx,%xmm0
divsd  0xd5e(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xdce(%rip),%rdi
call   1060 <logging_null@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"/sys/class/thermal/thermal_zone%u/trip_point_%d_type\00"
@.str.1 = [9 x i8] c"critical\00"
@.str.2 = [53 x i8] c"/sys/class/thermal/thermal_zone%u/trip_point_%d_temp\00"
@.str.3 = [54 x i8] c"a critical trip point has been found: %.2f degrees C\0A\00"
define i32 @sysfsparser_thermal_get_critical_temperature(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %37, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = call i8* @sysfsparser_getline(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp eq i8* null, %13
br i1 %14, label %15, label %16
15: ; preds = %9
br label %37
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %37
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = call i32 @sysfsparser_getvalue(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i32, i32* %5
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 1.000000e+03
%32 = fptrunc double %31 to float
%33 = call i32 @logging_null(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), float %32)
br label %34
34: ; preds = %28, %22
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
br label %40
37: ; preds = %21, %15
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %6
40: ; preds = %34, %6
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [53 x i8] c"/sys/class/thermal/thermal_zone%u/trip_point_%d_type\00"
@.str.1 = [9 x i8] c"critical\00"
@.str.2 = [53 x i8] c"/sys/class/thermal/thermal_zone%u/trip_point_%d_temp\00"
@.str.3 = [54 x i8] c"a critical trip point has been found: %.2f degrees C\0A\00"
define i32 @sysfsparser_thermal_get_critical_temperature(i32 %0) {
%2 = tail call i8* @sysfsparser_getline(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i32 0)
%3 = icmp eq i8* %2, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %37, %30, %23, %4
%9 = phi i32 [ 0, %4 ], [ 1, %23 ], [ 2, %30 ], [ 3, %37 ]
%10 = phi i8* [ %2, %4 ], [ %21, %23 ], [ %28, %30 ], [ %35, %37 ]
%11 = tail call i32 @sysfsparser_getvalue(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %9)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = sitofp i32 %11 to double
%15 = fdiv double %14, 1.000000e+03
%16 = fptrunc double %15 to float
%17 = tail call i32 @logging_null(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), float %16)
br label %18
18: ; preds = %13, %8
%19 = tail call i32 @free(i8* %10)
br label %41
20: ; preds = %4, %1
%21 = tail call i8* @sysfsparser_getline(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i32 1)
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %8, label %27
27: ; preds = %23, %20
%28 = tail call i8* @sysfsparser_getline(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i32 2)
%29 = icmp eq i8* %28, null
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %8, label %34
34: ; preds = %30, %27
%35 = tail call i8* @sysfsparser_getline(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i32 3)
%36 = icmp eq i8* %35, null
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %8, label %41
41: ; preds = %34, %37, %18
%42 = phi i32 [ %11, %18 ], [ -1, %37 ], [ -1, %34 ]
ret i32 %42
}