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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int odroid_open_file(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned long get_sensor_update_interval(char *sensor) {
  char ui_filename[64];
  int fd;
  char cdata[24];
  unsigned 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 0;
  }
  read_ret = read(fd, cdata, sizeof(cdata));
  close(fd);
  if (read_ret < 0) {
    return 0;
  }
  val = strtoul(cdata, NULL, 0);
  return val;
}


x86 assembly (clang, -O0):
<get_sensor_update_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe92(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1070 <odroid_open_file@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1196 <get_sensor_update_interval+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <get_sensor_update_interval+0x94>
mov    -0x54(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x18,%edx
call   1040 <read@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x7c(%rbp)
jge    11c9 <get_sensor_update_interval+0x79>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <get_sensor_update_interval+0x94>
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sensor_update_interval>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rdx
lea    0xea0(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <odroid_open_file@plt>
test   %eax,%eax
js     11a5 <get_sensor_update_interval+0x55>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
js     11a5 <get_sensor_update_interval+0x55>
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtoul@plt>
jmp    11a7 <get_sensor_update_interval+0x57>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.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 [64 x i8]
%5 = alloca i32
%6 = alloca [24 x i8]
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = call i32 @odroid_open_file(i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i64 0, i64* %2
br label %30
17: ; preds = %1
%18 = load i32, i32* %5
%19 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 24)
store i32 %20, i32* %8
%21 = load i32, i32* %5
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i64 0, i64* %2
br label %30
26: ; preds = %17
%27 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%28 = call i64 @strtoul(i8* %27, i32* null, i32 0)
store i64 %28, i64* %7
%29 = load i64, i64* %7
store i64 %29, i64* %2
br label %30
30: ; preds = %26, %25, %16
%31 = load i64, i64* %2
ret i64 %31
}

LLVM IR (-O2):
@.str = [45 x i8] c"/sys/bus/i2c/drivers/INA231/%s/update_period\00"
define i64 @get_sensor_update_interval(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%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 24)
%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 @strtoul(i8* nocapture %5, i32* null, i32 0)
br label %15
15: ; preds = %9, %1, %13
%16 = phi i64 [ %14, %13 ], [ 0, %1 ], [ 0, %9 ]
ret i64 %16
}