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

/* Variables and functions */
int BUFSIZ;
long atol(char *);
int /*<<< orphan*/ close(int);
int odroid_open_file(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
long get_sensor_update_interval(char *sensor) {
  char ui_filename[BUFSIZ];
  int fd;
  char cdata[BUFSIZ];
  long val;
  int read_ret;
  sprintf(ui_filename, "/sys/bus/i2c/drivers/INA231/%s/update_period", sensor);
  fd = odroid_open_file(ui_filename);
  if (fd < 0) {
    return -1;
  }
  read_ret = read(fd, cdata, sizeof(val));
  close(fd);
  if (read_ret < 0) {
    return -1;
  }
  val = atol(cdata);
  return val;
}


x86 assembly (clang, -O0):
<get_sensor_update_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe4f(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x48(%rbp),%rdi
call   1070 <odroid_open_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11e0 <get_sensor_update_interval+0x90>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
movl   $0x1,-0x40(%rbp)
jmp    1236 <get_sensor_update_interval+0xe6>
mov    -0x50(%rbp),%rsi
mov    -0x24(%rbp),%edi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x3c(%rbp)
jge    121a <get_sensor_update_interval+0xca>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
movl   $0x1,-0x40(%rbp)
jmp    1236 <get_sensor_update_interval+0xe6>
mov    -0x50(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sensor_update_interval>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rdx
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <odroid_open_file@plt>
mov    $0xffffffffffffffff,%r14
test   %eax,%eax
js     11ce <get_sensor_update_interval+0x7e>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1030 <close@plt>
test   %r12d,%r12d
js     11ce <get_sensor_update_interval+0x7e>
mov    %r15,%rdi
call   1050 <atol@plt>
mov    %rax,%r14
mov    %r14,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [45 x i8] c"/sys/bus/i2c/drivers/INA231/%s/update_period\00"
define i64 @get_sensor_update_interval(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i32, i32* @BUFSIZ
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
store i64 %16, i64* %7
%18 = load i8*, i8** %3
%19 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @odroid_open_file(i8* %14)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %1
store i64 -1, i64* %2
store i32 1, i32* %10
br label %35
24: ; preds = %1
%25 = load i32, i32* %6
%26 = call i32 @read(i32 %25, i8* %17, i32 8)
store i32 %26, i32* %9
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i64 -1, i64* %2
store i32 1, i32* %10
br label %35
32: ; preds = %24
%33 = call i64 @atol(i8* %17)
store i64 %33, i64* %8
%34 = load i64, i64* %8
store i64 %34, i64* %2
store i32 1, i32* %10
br label %35
35: ; preds = %32, %31, %23
%36 = load i8*, i8** %4
%37 = load i64, i64* %2
ret i64 %37
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [45 x i8] c"/sys/bus/i2c/drivers/INA231/%s/update_period\00"
define i64 @get_sensor_update_interval(i8* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = alloca i8, i64 %3
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @odroid_open_file(i8* %4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = call i32 @read(i32 %7, i8* %5, i32 8)
%11 = call i32 @close(i32 %7)
%12 = icmp slt i32 %10, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i64 @atol(i8* %5)
br label %15
15: ; preds = %9, %1, %13
%16 = phi i64 [ %14, %13 ], [ -1, %1 ], [ -1, %9 ]
ret i64 %16
}