#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void put_nvidia_temp(char *out, void *arg) {
  FILE *fp = popen("/usr/bin/nvidia-settings -q gpucoretemp -t", "r");
  if (fp == NULL) {
    sprintf(out, "??°C");
    return;
  }
  int temp;
  if (fscanf(fp, "%d", &temp) != 1) {
    sprintf(out, "??°C");
    fclose(fp);
    return;
  }
  fclose(fp);
  sprintf(out, "%2d°C", temp);
}


x86 assembly (clang, -O0):
<put_nvidia_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea9(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <put_nvidia_temp+0x49>
mov    -0x8(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    11e4 <put_nvidia_temp+0xa4>
mov    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11c6 <put_nvidia_temp+0x86>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e4 <put_nvidia_temp+0xa4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_nvidia_temp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xed6(%rip),%rsi
call   1050 <popen@plt>
test   %rax,%rax
je     119a <put_nvidia_temp+0x5a>
mov    %rax,%rbx
lea    0xeca(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11aa <put_nvidia_temp+0x6a>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%edx
lea    0xea8(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    11c0 <put_nvidia_temp+0x80>
movw   $0x43,0x4(%r14)
movl   $0xb0c23f3f,(%r14)
jmp    11c0 <put_nvidia_temp+0x80>
movw   $0x43,0x4(%r14)
movl   $0xb0c23f3f,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"/usr/bin/nvidia-settings -q gpucoretemp -t\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"??\C2\B0C\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"%2d\C2\B0C\00"
define void @put_nvidia_temp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = call i32* @popen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
br label %28
22: ; preds = %13
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22, %17, %10
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"/usr/bin/nvidia-settings -q gpucoretemp -t\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"??\C2\B0C\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"%2d\C2\B0C\00"
define void @put_nvidia_temp(i8* nocapture writeonly %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32* @popen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) %0, i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6, i1 false)
br label %18
7: ; preds = %2
%8 = bitcast i32* %3 to i8*
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @fclose(i32* %4)
br label %17
13: ; preds = %7
%14 = call i32 @fclose(i32* %4)
%15 = load i32, i32* %3
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %11
br label %18
18: ; preds = %17, %6
ret void
}