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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned int read(int, char *, int);
double get_i2c_info(int fd, int div) {
  int val = 0;
  if (fd <= 0)
    return 0;
  lseek(fd, 0, SEEK_SET);
  {
    char buf[64];
    unsigned int n;
    n = read(fd, buf, 63);
    buf[n] = '\0';
    val = atoi(buf);
  }
  if (div > 1)
    return val / div;
  else if (div)
    return val / 1000.0;
  else
    return val;
}


x86 assembly (clang, -O0):
<get_i2c_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     115c <get_i2c_info+0x2c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <get_i2c_info+0xb5>
mov    -0xc(%rbp),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x3f,%edx
call   1040 <read@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x10(%rbp)
jle    11b6 <get_i2c_info+0x86>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <get_i2c_info+0xb5>
cmpl   $0x0,-0x10(%rbp)
je     11db <get_i2c_info+0xab>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e5 <get_i2c_info+0xb5>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_i2c_info>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
test   %edi,%edi
jle    117e <get_i2c_info+0x4e>
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rsp,%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x3f,%edx
call   1040 <read@plt>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1050 <atoi@plt>
cmp    $0x2,%ebx
jl     1184 <get_i2c_info+0x54>
cltd
idiv   %ebx
cvtsi2sd %eax,%xmm0
jmp    1194 <get_i2c_info+0x64>
xorpd  %xmm0,%xmm0
jmp    1194 <get_i2c_info+0x64>
cvtsi2sd %eax,%xmm0
test   %ebx,%ebx
je     1194 <get_i2c_info+0x64>
divsd  0xe6c(%rip),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define double @get_i2c_info(i32 %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store double 0.000000e+00, double* %3
br label %41
12: ; preds = %2
%13 = load i32, i32* %4
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 0, i32 %14)
%16 = load i32, i32* %4
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 63)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %12
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = sdiv i32 %27, %28
%30 = sitofp i32 %29 to double
store double %30, double* %3
br label %41
31: ; preds = %12
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %6
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, 1.000000e+03
store double %37, double* %3
br label %41
38: ; preds = %31
%39 = load i32, i32* %6
%40 = sitofp i32 %39 to double
store double %40, double* %3
br label %41
41: ; preds = %38, %34, %26, %11
%42 = load double, double* %3
ret double %42
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define double @get_i2c_info(i32 %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = icmp slt i32 %0, 1
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %0, i32 0, i32 %6)
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %0, i8* %8, i32 63)
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @atoi(i8* %8)
%13 = icmp sgt i32 %1, 1
br i1 %13, label %14, label %17
14: ; preds = %5
%15 = sdiv i32 %12, %1
%16 = sitofp i32 %15 to double
br label %22
17: ; preds = %5
%18 = icmp eq i32 %1, 0
%19 = sitofp i32 %12 to double
br i1 %18, label %22, label %20
20: ; preds = %17
%21 = fdiv double %19, 1.000000e+03
br label %22
22: ; preds = %17, %2, %20, %14
%23 = phi double [ %16, %14 ], [ %21, %20 ], [ 0.000000e+00, %2 ], [ %19, %17 ]
ret double %23
}