#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*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int snprintf0(char *, int, char *, char *);
scalar_t__ sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int fill_temp(char *str, int n, const char *sensor) {
  FILE *sensors = popen("sensors", "r");
  if (NULL == sensors) {
    fprintf(stderr, "Could not open the 'sensors' command\n");
    exit(1);
  }
  char line[256];
  int sensor_len = strlen(sensor);
  while (NULL != fgets(line, 256, sensors)) {
    if (0 == strncmp(sensor, line, sensor_len)) {
      char reading[64];
      if (0 == sscanf(line + sensor_len + 1, "%s", reading)) {
        goto notfound;
      }
      pclose(sensors);
      int readinglen = strlen(reading);
      reading[readinglen - 5] = reading[readinglen - 1];
      reading[readinglen - 4] = '\0';
      return snprintf0(str, n, "%3s", reading + 1);
    }
  }
notfound:
  pclose(sensors);
  fprintf(stderr, "Could not find '%s' in sensors\n", sensor);
  exit(1);
}


x86 assembly (clang, -O0):
<fill_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe53(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11ea <fill_temp+0x5a>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12f9 <fill_temp+0x169>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12f4 <fill_temp+0x164>
lea    -0x120(%rbp),%rdi
movslq -0x124(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x170(%rbp),%rdx
lea    0xdcd(%rip),%rsi
call   1080 <sscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    127b <fill_temp+0xeb>
jmp    12fe <fill_temp+0x16e>
mov    -0x20(%rbp),%rdi
call   1050 <pclose@plt>
lea    -0x170(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x174(%rbp)
mov    -0x174(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x170(%rbp,%rax,1),%cl
mov    -0x174(%rbp),%eax
sub    $0x5,%eax
cltq
mov    %cl,-0x170(%rbp,%rax,1)
mov    -0x174(%rbp),%eax
sub    $0x4,%eax
cltq
movb   $0x0,-0x170(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x170(%rbp),%rcx
add    $0x1,%rcx
lea    0xd4d(%rip),%rdx
call   1090 <snprintf0@plt>
add    $0x180,%rsp
pop    %rbp
ret
jmp    11f9 <fill_temp+0x69>
jmp    12fe <fill_temp+0x16e>
mov    -0x20(%rbp),%rdi
call   1050 <pclose@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<fill_temp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xe4f(%rip),%rdi
lea    0xe50(%rip),%rsi
call   10a0 <popen@plt>
test   %rax,%rax
je     129d <fill_temp+0x10d>
mov    %rax,%r13
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x40(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1271 <fill_temp+0xe1>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11e0 <fill_temp+0x50>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x41,%rdi
lea    0xe17(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
call   1080 <sscanf@plt>
test   %rax,%rax
je     1271 <fill_temp+0xe1>
mov    %r13,%rdi
call   1050 <pclose@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
mov    -0x1(%rax,%rbx,1),%cl
mov    %cl,-0x5(%rax,%rbx,1)
movb   $0x0,-0x4(%rax,%rbx,1)
lea    0x1(%rsp),%rcx
lea    0xddf(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <snprintf0@plt>
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
call   1050 <pclose@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"sensors\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Could not open the 'sensors' command\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"%3s\00"
@.str.5 = [32 x i8] c"Could not find '%s' in sensors\0A\00"
define i32 @fill_temp(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca [64 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%12 = call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %9
br label %22
22: ; preds = %66, %19
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = load i32*, i32** %7
%25 = call i32* @fgets(i8* %23, i32 256, i32* %24)
%26 = icmp ne i32* null, %25
br i1 %26, label %27, label %67
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %9
%31 = call i64 @strncmp(i8* %28, i8* %29, i32 %30)
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %66
33: ; preds = %27
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%40 = call i64 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = icmp eq i64 0, %40
br i1 %41, label %42, label %43
42: ; preds = %33
br label %68
43: ; preds = %33
%44 = load i32*, i32** %7
%45 = call i32 @pclose(i32* %44)
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = load i32, i32* %11
%54 = sub nsw i32 %53, 5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %55
store i8 %52, i8* %56
%57 = load i32, i32* %11
%58 = sub nsw i32 %57, 4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %4
%62 = load i32, i32* %5
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = call i32 @snprintf0(i8* %61, i32 %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %64)
ret i32 %65
66: ; preds = %27
br label %22
67: ; preds = %22
br label %68
68: ; preds = %67, %42
%69 = load i32*, i32** %7
%70 = call i32 @pclose(i32* %69)
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %6
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"sensors\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Could not open the 'sensors' command\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"%3s\00"
@.str.5 = [32 x i8] c"Could not find '%s' in sensors\0A\00"
define i32 @fill_temp(i8* %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca [64 x i8]
%6 = tail call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = tail call i32 @strlen(i8* %2)
br label %15
15: ; preds = %18, %12
%16 = call i32* @fgets(i8* %13, i32 256, i32* %6)
%17 = icmp eq i32* %16, null
br i1 %17, label %29, label %18
18: ; preds = %15
%19 = call i64 @strncmp(i8* %2, i8* %13, i32 %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %18
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%23 = sext i32 %14 to i64
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i64 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %21
br label %29
29: ; preds = %15, %28
%30 = call i32 @pclose(i32* %6)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %21
%35 = call i32 @pclose(i32* %6)
%36 = call i32 @strlen(i8* %22)
%37 = add nsw i32 %36, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = add nsw i32 %36, -5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %42
store i8 %40, i8* %43
%44 = add nsw i32 %36, -4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 1
%48 = call i32 @snprintf0(i8* %0, i32 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %47)
ret i32 %48
}