#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 NAME_MAX;
float convertTemperature(unsigned int, unsigned int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *, unsigned int *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char readSensor(float *reading, char *deviceId) {
  FILE *fp;
  char fName[NAME_MAX];
  unsigned int hexout[10];
  int result = (1 == 1);
  snprintf(fName, NAME_MAX,
           "/sys/bus/w1/drivers/w1_master_driver/w1_bus_master1"
           "/%s/w1_slave",
           deviceId);
  fp = fopen(fName, "r");
  if (fp == NULL) {
    return (1 == 2);
  }
  if (fscanf(fp, "%x %x %x %x %x %x %x %x %x : crc=%x YES", &hexout[0],
             &hexout[1], &hexout[2], &hexout[3], &hexout[4], &hexout[5],
             &hexout[6], &hexout[7], &hexout[8], &hexout[9]) != 10) {
    result = (1 == 2);
  } else {
    *reading = convertTemperature(hexout[1], hexout[0]);
  }
  fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<readSensor>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x1,-0x74(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rcx
lea    0xe54(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x80(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e0 <readSensor+0x90>
movb   $0x0,-0x19(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    129f <readSensor+0x14f>
mov    -0x38(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    -0x70(%rbp),%rcx
add    $0x4,%rcx
lea    -0x70(%rbp),%r8
add    $0x8,%r8
lea    -0x70(%rbp),%r9
add    $0xc,%r9
lea    -0x70(%rbp),%r15
add    $0x10,%r15
lea    -0x70(%rbp),%r14
add    $0x14,%r14
lea    -0x70(%rbp),%rbx
add    $0x18,%rbx
lea    -0x70(%rbp),%r11
add    $0x1c,%r11
lea    -0x70(%rbp),%r10
add    $0x20,%r10
lea    -0x70(%rbp),%rax
add    $0x24,%rax
lea    0xe0b(%rip),%rsi
sub    $0x30,%rsp
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1050 <fscanf@plt>
add    $0x30,%rsp
cmp    $0xa,%eax
je     1276 <readSensor+0x126>
movl   $0x0,-0x74(%rbp)
jmp    1289 <readSensor+0x139>
mov    -0x6c(%rbp),%edi
mov    -0x70(%rbp),%esi
call   1060 <convertTemperature@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x74(%rbp),%eax
mov    %al,-0x19(%rbp)
movl   $0x1,-0x78(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
movsbl -0x19(%rbp),%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<readSensor>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rcx
mov    %rdi,%r14
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe75(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1208 <readSensor+0xb8>
mov    %rax,%r15
lea    -0x4c(%rbp),%rcx
lea    -0x48(%rbp),%r8
lea    -0x44(%rbp),%r9
lea    -0x40(%rbp),%r10
lea    -0x3c(%rbp),%r11
lea    -0x38(%rbp),%r12
lea    -0x34(%rbp),%r13
lea    -0x30(%rbp),%rax
lea    -0x2c(%rbp),%rbx
lea    0xe6d(%rip),%rsi
lea    -0x50(%rbp),%rdx
mov    %r15,%rdi
push   %rbx
push   %rax
push   %r13
push   %r12
push   %r11
push   %r10
call   1050 <fscanf@plt>
add    $0x30,%rsp
cmp    $0xa,%eax
jne    120c <readSensor+0xbc>
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%edi
call   1060 <convertTemperature@plt>
movss  %xmm0,(%r14)
mov    $0x1,%bl
jmp    120e <readSensor+0xbe>
xor    %ebx,%ebx
jmp    1216 <readSensor+0xc6>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NAME_MAX = global i32 0
@.str = [64 x i8] c"/sys/bus/w1/drivers/w1_master_driver/w1_bus_master1/%s/w1_slave\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"%x %x %x %x %x %x %x %x %x : crc=%x YES\00"
define signext i8 @readSensor(float* %0, i8* %1) {
%3 = alloca i8
%4 = alloca float*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [10 x i32]
%10 = alloca i32
%11 = alloca i32
store float* %0, float** %4
store i8* %1, i8** %5
%12 = load i32, i32* @NAME_MAX
%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
store i32 1, i32* %10
%16 = load i32, i32* @NAME_MAX
%17 = load i8*, i8** %5
%18 = call i32 @snprintf(i8* %15, i32 %16, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %2
store i8 0, i8* %3
store i32 1, i32* %11
br label %50
23: ; preds = %2
%24 = load i32*, i32** %6
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 2
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 3
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 4
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 5
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 6
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 7
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 8
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 9
%35 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32* %25, i32* %26, i32* %27, i32* %28, i32* %29, i32* %30, i32* %31, i32* %32, i32* %33, i32* %34)
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %23
store i32 0, i32* %10
br label %45
38: ; preds = %23
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%42 = load i32, i32* %41
%43 = call float @convertTemperature(i32 %40, i32 %42)
%44 = load float*, float** %4
store float %43, float* %44
br label %45
45: ; preds = %38, %37
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %10
%49 = trunc i32 %48 to i8
store i8 %49, i8* %3
store i32 1, i32* %11
br label %50
50: ; preds = %45, %22
%51 = load i8*, i8** %7
%52 = load i8, i8* %3
ret i8 %52
}

LLVM IR (-O2):
@NAME_MAX = global i32 0
@.str = [64 x i8] c"/sys/bus/w1/drivers/w1_master_driver/w1_bus_master1/%s/w1_slave\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"%x %x %x %x %x %x %x %x %x : crc=%x YES\00"
define signext i8 @readSensor(float* nocapture writeonly %0, i8* %1) {
%3 = alloca [10 x i32]
%4 = load i32, i32* @NAME_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast [10 x i32]* %3 to i8*
%8 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %31, label %11
11: ; preds = %2
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 7
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 8
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%22 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32* %12, i32* %13, i32* %14, i32* %15, i32* %16, i32* %17, i32* %18, i32* %19, i32* %20, i32* %21)
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %28
24: ; preds = %11
%25 = load i32, i32* %13
%26 = load i32, i32* %12
%27 = call float @convertTemperature(i32 %25, i32 %26)
store float %27, float* %0
br label %28
28: ; preds = %11, %24
%29 = phi i8 [ 1, %24 ], [ 0, %11 ]
%30 = call i32 @fclose(i32* %9)
br label %31
31: ; preds = %2, %28
%32 = phi i8 [ %29, %28 ], [ 0, %2 ]
ret i8 %32
}