#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 PATH_MAX;
int get_value(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int read_elapsed_time(char *region, unsigned long *elapsed) {
  int ret;
  char val[32];
  char path[PATH_MAX];
  *elapsed = 0;
  sprintf(path,
          "/sys/kernel/debug"
          "/o2hb"
          "/%s/elapsed_time_in_ms",
          region);
  ret = get_value(path, val, sizeof(val));
  if (ret)
    goto bail;
  *elapsed = strtoul(val, NULL, 0);
  ret = 0;
bail:
  return ret;
}


x86 assembly (clang, -O0):
<read_elapsed_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1030 <get_value@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ab <read_elapsed_time+0x7b>
jmp    11cb <read_elapsed_time+0x9b>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_elapsed_time>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rdx
mov    %rsp,%r15
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movq   $0x0,(%rsi)
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    -0x40(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x20,%edx
call   1030 <get_value@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    119d <read_elapsed_time+0x6d>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r14)
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [45 x i8] c"/sys/kernel/debug/o2hb/%s/elapsed_time_in_ms\00"
define i32 @read_elapsed_time(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
%13 = load i64*, i64** %4
store i64 0, i64* %13
%14 = load i8*, i8** %3
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%17 = call i32 @get_value(i8* %12, i8* %16, i32 32)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
br label %25
21: ; preds = %2
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%23 = call i64 @strtoul(i8* %22, i32* null, i32 0)
%24 = load i64*, i64** %4
store i64 %23, i64* %24
store i32 0, i32* %5
br label %25
25: ; preds = %21, %20
%26 = load i32, i32* %5
%27 = load i8*, i8** %7
ret i32 %26
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [45 x i8] c"/sys/kernel/debug/o2hb/%s/elapsed_time_in_ms\00"
define i32 @read_elapsed_time(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
store i64 0, i64* %1
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @get_value(i8* %8, i8* %4, i32 32)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 0)
store i64 %13, i64* %1
br label %14
14: ; preds = %2, %12
ret i32 %10
}