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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char const *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stdout;
int thermal_info(const char *prefix, const char *format,
                 const char *delimeter) {
  bool first = false;
  for (int i = 0; i < 10; i++) {
    char path[256];
    snprintf(path, 256, "/sys/class/thermal/thermal_zone%d/temp", i);
    FILE *f = fopen(path, "r");
    if (!f)
      break;
    int temp;
    if (fscanf(f, "%d", &temp) == 1) {
      printf("%s", first ? delimeter : prefix);
      printf(format, temp / 1000);
      first = true;
    }
    fclose(f);
  }
  putchar('\n');
  fflush(stdout);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<thermal_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    1280 <thermal_info+0x110>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    $0x100,%esi
lea    0xe4b(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11e7 <thermal_info+0x77>
jmp    1280 <thermal_info+0x110>
mov    -0x128(%rbp),%rdi
lea    0xe34(%rip),%rsi
lea    -0x12c(%rbp),%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    1266 <thermal_info+0xf6>
cmpl   $0x0,-0x1c(%rbp)
je     1224 <thermal_info+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x138(%rbp)
jmp    122f <thermal_info+0xbf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x12c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1195 <thermal_info+0x25>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thermal_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
lea    0x20(%rsp),%rbx
lea    0xe8b(%rip),%rbp
lea    0x4(%rsp),%r15
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11c6 <thermal_info+0x56>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x1,%r12d
cmp    $0xa,%r12d
je     1253 <thermal_info+0xe3>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xe2b(%rip),%rdx
mov    %r12d,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1253 <thermal_info+0xe3>
mov    %rax,%r13
mov    %rax,%rdi
lea    0xe2f(%rip),%rsi
mov    %r15,%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    11b0 <thermal_info+0x40>
test   %r14d,%r14d
mov    0x18(%rsp),%rsi
cmove  0x8(%rsp),%rsi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x4(%rsp),%rax
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
mov    0x10(%rsp),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14d
jmp    11b0 <thermal_info+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"/sys/class/thermal/thermal_zone%d/temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%s\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @thermal_info(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %45, %3
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %48
15: ; preds = %12
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%17 = load i32, i32* %8
%18 = call i32 @snprintf(i8* %16, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %15
br label %48
24: ; preds = %15
%25 = load i32*, i32** %10
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load i8*, i8** %6
br label %35
33: ; preds = %28
%34 = load i8*, i8** %4
br label %35
35: ; preds = %33, %31
%36 = phi i8* [ %32, %31 ], [ %34, %33 ]
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %5
%39 = load i32, i32* %11
%40 = sdiv i32 %39, 1000
%41 = call i32 (i8*, ...) @printf(i8* %38, i32 %40)
store i32 1, i32* %7
br label %42
42: ; preds = %35, %24
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %12
48: ; preds = %23, %12
%49 = call i32 @putchar(i8 signext 10)
%50 = load i32, i32* @stdout
%51 = call i32 @fflush(i32 %50)
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@.str = [39 x i8] c"/sys/class/thermal/thermal_zone%d/temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%s\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @thermal_info(i8* %0, i8* nocapture %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
br label %8
8: ; preds = %3, %25
%9 = phi i32 [ 0, %3 ], [ %26, %25 ]
%10 = phi i32 [ 0, %3 ], [ %28, %25 ]
%11 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %8
br label %30
15: ; preds = %8
%16 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = icmp eq i32 %9, 0
%20 = select i1 %19, i8* %0, i8* %2
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %5
%23 = sdiv i32 %22, 1000
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %1, i32 %23)
br label %25
25: ; preds = %18, %15
%26 = phi i32 [ 1, %18 ], [ %9, %15 ]
%27 = call i32 @fclose(i32* %12)
%28 = add nuw nsw i32 %10, 1
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %8
30: ; preds = %25, %14
%31 = call i32 @putchar(i8 signext 10)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}