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

/* Variables and functions */
int BUFSIZ;
scalar_t__ spawn_sync_read(char const *, char const **, int, char *);
int sscanf(char *, char *, int *);
int sensors_nvidia(const char *setting, int *val) {
  const char *argv[] = {"nvidia-settings", "-q", NULL, NULL};
  char out[BUFSIZ];
  int dummy;
  argv[2] = (char *)setting;
  if (val == NULL) {
    val = &dummy;
  }
  if (spawn_sync_read(argv[0], argv, sizeof(out), out) < 0) {
    return -1;
  }
  if (sscanf(out, " Attribute %*s %*s %d", val) != 1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sensors_nvidia>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movaps 0x2cc9(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0x2cae(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1191 <sensors_nvidia+0x71>
lea    -0x54(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x68(%rbp),%rax
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <spawn_sync_read@plt>
cmp    $0x0,%rax
jge    11c5 <sensors_nvidia+0xa5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    1203 <sensors_nvidia+0xe3>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11f5 <sensors_nvidia+0xd5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    1203 <sensors_nvidia+0xe3>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensors_nvidia>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rsp,%r15
movaps 0x2cc6(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0x2cab(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rdi,-0x30(%rbp)
lea    0xe8f(%rip),%rdi
lea    -0x40(%rbp),%rsi
mov    %rbx,%rcx
call   1030 <spawn_sync_read@plt>
test   %rax,%rax
js     11aa <sensors_nvidia+0x8a>
test   %r14,%r14
lea    -0x1c(%rbp),%rdx
cmovne %r14,%rdx
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
neg    %eax
jmp    11af <sensors_nvidia+0x8f>
mov    $0xffffffff,%eax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"nvidia-settings\00"
@.str.1 = [3 x i8] c"-q\00"
@__const.sensors_nvidia.argv = [4 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@BUFSIZ = global i32 0
@.str.2 = [22 x i8] c" Attribute %*s %*s %d\00"
define i32 @sensors_nvidia(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4 x i8*]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%11 = bitcast [4 x i8*]* %6 to i8*
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 2
store i8* %16, i8** %17
%18 = load i32*, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %2
store i32* %9, i32** %5
br label %21
21: ; preds = %20, %2
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%25 = trunc i64 %13 to i32
%26 = call i64 @spawn_sync_read(i8* %23, i8** %24, i32 %25, i8* %15)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 -1, i32* %3
store i32 1, i32* %10
br label %35
29: ; preds = %21
%30 = load i32*, i32** %5
%31 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 -1, i32* %3
store i32 1, i32* %10
br label %35
34: ; preds = %29
store i32 0, i32* %3
store i32 1, i32* %10
br label %35
35: ; preds = %34, %33, %28
%36 = load i8*, i8** %7
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [16 x i8] c"nvidia-settings\00"
@.str.1 = [3 x i8] c"-q\00"
@__const.sensors_nvidia.argv = [4 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@BUFSIZ = global i32 0
@.str.2 = [22 x i8] c" Attribute %*s %*s %d\00"
define i32 @sensors_nvidia(i8* %0, i32* %1) {
%3 = alloca [4 x i8*]
%4 = alloca i32
%5 = bitcast [4 x i8*]* %3 to i8*
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
store i8* %0, i8** %11
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%13 = call i64 @spawn_sync_read(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %12, i32 %6, i8* %9)
%14 = icmp slt i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = icmp eq i32* %1, null
%17 = select i1 %16, i32* %4, i32* %1
%18 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32* %17)
%19 = icmp ne i32 %18, 1
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %15, %2
%22 = phi i32 [ -1, %2 ], [ %20, %15 ]
ret i32 %22
}