#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 */
struct inv_sysfs_names_s {
  int dummy;
};

/* Variables and functions */
scalar_t__ inv_read_temp_offset(struct inv_sysfs_names_s const *, short *);
scalar_t__ inv_read_temp_scale(struct inv_sysfs_names_s const *, short *);
scalar_t__ inv_read_temperature_raw(struct inv_sysfs_names_s const *, short *,
                                    long long *);
int inv_read_temp_q16(const struct inv_sysfs_names_s *names, long *data,
                      long long *timestamp) {
  int count = 0;
  short raw;
  static short scale, offset;
  static unsigned char first_read = 1;
  if (first_read) {
    count += inv_read_temp_scale(names, &scale);
    count += inv_read_temp_offset(names, &offset);
    first_read = 0;
  }
  count += inv_read_temperature_raw(names, &raw, timestamp);
  data[0] = (long)((35 + ((float)(raw - offset) / scale)) * 65536.f);
  return count;
}


x86 assembly (clang, -O0):
<inv_read_temp_q16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpb   $0x0,0x2ee6(%rip)
je     1199 <inv_read_temp_q16+0x69>
mov    -0x8(%rbp),%rdi
lea    0x2ed9(%rip),%rsi
call   1050 <inv_read_temp_scale@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0x2ebe(%rip),%rsi
call   1040 <inv_read_temp_offset@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
movb   $0x0,0x2e9f(%rip)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x1e(%rbp),%rsi
call   1030 <inv_read_temperature_raw@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
movswl -0x1e(%rbp),%eax
movswl 0x2e7c(%rip),%ecx
sub    %ecx,%eax
cvtsi2ss %eax,%xmm1
movswl 0x2e6d(%rip),%eax
cvtsi2ss %eax,%xmm0
divss  %xmm0,%xmm1
movss  0xe25(%rip),%xmm0
addss  %xmm1,%xmm0
movss  0xe15(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_read_temp_q16>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x0,0x2ef6(%rip)
je     114f <inv_read_temp_q16+0x1f>
xor    %r12d,%r12d
jmp    117d <inv_read_temp_q16+0x4d>
lea    0x2ee4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <inv_read_temp_scale@plt>
mov    %rax,%r12
lea    0x2ed4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <inv_read_temp_offset@plt>
add    %r12d,%eax
movb   $0x1,0x2ec4(%rip)
movslq %eax,%r12
lea    0x6(%rsp),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <inv_read_temperature_raw@plt>
movswl 0x6(%rsp),%ecx
movswl 0x2ea3(%rip),%edx
sub    %edx,%ecx
cvtsi2ss %ecx,%xmm0
movswl 0x2e94(%rip),%ecx
cvtsi2ss %ecx,%xmm1
divss  %xmm1,%xmm0
addss  0xe4a(%rip),%xmm0
mulss  0xe46(%rip),%xmm0
add    %r12d,%eax
cvttss2si %xmm0,%rcx
mov    %rcx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.inv_sysfs_names_s = type { i32 }
@inv_read_temp_q16.scale = internal global i16 0
@inv_read_temp_q16.offset = internal global i16 0
@inv_read_temp_q16.first_read = internal global i8 1
define i32 @inv_read_temp_q16(%struct.inv_sysfs_names_s* %0, i64* %1, i64* %2) {
%4 = alloca %struct.inv_sysfs_names_s*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i16
store %struct.inv_sysfs_names_s* %0, %struct.inv_sysfs_names_s** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
store i32 0, i32* %7
%9 = load i8, i8* @inv_read_temp_q16.first_read
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = load %struct.inv_sysfs_names_s*, %struct.inv_sysfs_names_s** %4
%13 = call i64 @inv_read_temp_scale(%struct.inv_sysfs_names_s* %12, i16* @inv_read_temp_q16.scale)
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load %struct.inv_sysfs_names_s*, %struct.inv_sysfs_names_s** %4
%19 = call i64 @inv_read_temp_offset(%struct.inv_sysfs_names_s* %18, i16* @inv_read_temp_q16.offset)
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %7
store i8 0, i8* @inv_read_temp_q16.first_read
br label %24
24: ; preds = %11, %3
%25 = load %struct.inv_sysfs_names_s*, %struct.inv_sysfs_names_s** %4
%26 = load i64*, i64** %6
%27 = call i64 @inv_read_temperature_raw(%struct.inv_sysfs_names_s* %25, i16* %8, i64* %26)
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
%32 = load i16, i16* %8
%33 = sext i16 %32 to i32
%34 = load i16, i16* @inv_read_temp_q16.offset
%35 = sext i16 %34 to i32
%36 = sub nsw i32 %33, %35
%37 = sitofp i32 %36 to float
%38 = load i16, i16* @inv_read_temp_q16.scale
%39 = sext i16 %38 to i32
%40 = sitofp i32 %39 to float
%41 = fdiv float %37, %40
%42 = fadd float 3.500000e+01, %41
%43 = fmul float %42, 6.553600e+04
%44 = fptosi float %43 to i64
%45 = load i64*, i64** %5
%46 = getelementptr inbounds i64, i64* %45, i64 0
store i64 %44, i64* %46
%47 = load i32, i32* %7
ret i32 %47
}

LLVM IR (-O2):
%struct.inv_sysfs_names_s = type { i32 }
@inv_read_temp_q16.scale = internal global i16 0
@inv_read_temp_q16.offset = internal global i16 0
@inv_read_temp_q16.first_read = internal unnamed_addr global i1 false
define i32 @inv_read_temp_q16(%struct.inv_sysfs_names_s* %0, i64* nocapture writeonly %1, i64* %2) {
%4 = alloca i16
%5 = bitcast i16* %4 to i8*
%6 = load i1, i1* @inv_read_temp_q16.first_read
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i64 @inv_read_temp_scale(%struct.inv_sysfs_names_s* %0, i16* @inv_read_temp_q16.scale)
%9 = tail call i64 @inv_read_temp_offset(%struct.inv_sysfs_names_s* %0, i16* @inv_read_temp_q16.offset)
%10 = add i64 %9, %8
store i1 true, i1* @inv_read_temp_q16.first_read
%11 = shl i64 %10, 32
%12 = ashr exact i64 %11, 32
br label %13
13: ; preds = %7, %3
%14 = phi i64 [ %12, %7 ], [ 0, %3 ]
%15 = call i64 @inv_read_temperature_raw(%struct.inv_sysfs_names_s* %0, i16* %4, i64* %2)
%16 = add nsw i64 %15, %14
%17 = trunc i64 %16 to i32
%18 = load i16, i16* %4
%19 = sext i16 %18 to i32
%20 = load i16, i16* @inv_read_temp_q16.offset
%21 = sext i16 %20 to i32
%22 = sub nsw i32 %19, %21
%23 = sitofp i32 %22 to float
%24 = load i16, i16* @inv_read_temp_q16.scale
%25 = sitofp i16 %24 to float
%26 = fdiv float %23, %25
%27 = fadd float %26, 3.500000e+01
%28 = fmul float %27, 6.553600e+04
%29 = fptosi float %28 to i64
store i64 %29, i64* %1
ret i32 %17
}