#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 getSysFileValue(char *, int, char *);
int /*<<< orphan*/ output(char *, ...);
scalar_t__ sscanf(char const *, char *, int *);
void printSysThermalZoneTemperature(const char *cmd) {
  int zone = 0;
  if (sscanf(cmd, "acpi/Thermal_Zone/%d", &zone) <= 0) {
    output("-1\n");
    return;
  }
  output("%d\n", getSysFileValue("thermal_zone", zone, "temp") / 1000);
}


x86 assembly (clang, -O0):
<printSysThermalZoneTemperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x0,%rax
jg     1174 <printSysThermalZoneTemperature+0x44>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
jmp    11a2 <printSysThermalZoneTemperature+0x72>
mov    -0xc(%rbp),%esi
lea    0xe9f(%rip),%rdi
lea    0xea5(%rip),%rdx
call   1040 <getSysFileValue@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSysThermalZoneTemperature>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xec0(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <sscanf@plt>
test   %rax,%rax
jle    118c <printSysThermalZoneTemperature+0x5c>
mov    0x4(%rsp),%esi
lea    0xec3(%rip),%rdi
lea    0xec9(%rip),%rdx
call   1040 <getSysFileValue@plt>
cltq
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
pop    %rax
ret
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [21 x i8] c"acpi/Thermal_Zone/%d\00"
@.str.1 = [4 x i8] c"-1\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [13 x i8] c"thermal_zone\00"
@.str.4 = [5 x i8] c"temp\00"
define void @printSysThermalZoneTemperature(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = call i64 @sscanf(i8* %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp sle i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %14
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @getSysFileValue(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%12 = sdiv i32 %11, 1000
%13 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %9, %7
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"acpi/Thermal_Zone/%d\00"
@.str.1 = [4 x i8] c"-1\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [13 x i8] c"thermal_zone\00"
@.str.4 = [5 x i8] c"temp\00"
define void @printSysThermalZoneTemperature(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp slt i64 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @getSysFileValue(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%11 = sdiv i32 %10, 1000
%12 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %8, %6
ret void
}