#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*/ free(char *);
int /*<<< orphan*/ util_file_read_l(long *, int, char *);
char *util_path_sysfs(char *, char *);
scalar_t__ util_sys_get_dev_addr(char *, char *);
int dasd_get_host_access_count(char *device) {
  char busid[9];
  char *path;
  long value;
  if (util_sys_get_dev_addr(device, busid) != 0)
    return 0;
  path = util_path_sysfs("bus/ccw/devices/%s/host_access_count", busid);
  util_file_read_l(&value, 10, path);
  free(path);
  return value;
}


x86 assembly (clang, -O0):
<dasd_get_host_access_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x19(%rbp),%rsi
call   1040 <util_sys_get_dev_addr@plt>
cmp    $0x0,%rax
je     116f <dasd_get_host_access_count+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <dasd_get_host_access_count+0x65>
lea    -0x19(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1050 <util_path_sysfs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1060 <util_file_read_l@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dasd_get_host_access_count>:
push   %rbx
sub    $0x20,%rsp
lea    0x17(%rsp),%rsi
call   1040 <util_sys_get_dev_addr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    118b <dasd_get_host_access_count+0x4b>
lea    0xea0(%rip),%rdi
lea    0x17(%rsp),%rsi
call   1050 <util_path_sysfs@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1060 <util_file_read_l@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"bus/ccw/devices/%s/host_access_count\00"
define i32 @dasd_get_host_access_count(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [9 x i8]
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%9 = call i64 @util_sys_get_dev_addr(i8* %7, i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %21
12: ; preds = %1
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%14 = call i8* @util_path_sysfs(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @util_file_read_l(i64* %6, i32 10, i8* %15)
%17 = load i8*, i8** %5
%18 = call i32 @free(i8* %17)
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %12, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [37 x i8] c"bus/ccw/devices/%s/host_access_count\00"
define i32 @dasd_get_host_access_count(i8* %0) {
%2 = alloca [9 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = bitcast i64* %3 to i8*
%6 = call i64 @util_sys_get_dev_addr(i8* %0, i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = call i8* @util_path_sysfs(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = call i32 @util_file_read_l(i64* %3, i32 10, i8* %9)
%11 = call i32 @free(i8* %9)
%12 = load i64, i64* %3
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %1, %8
%15 = phi i32 [ %13, %8 ], [ 0, %1 ]
ret i32 %15
}