#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 ENODEV;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ asprintf(char **, char *, char const *, int);
int find_type_by_name(char *, char *);
int /*<<< orphan*/ free(char *);
int read_sysfs_posint(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int __read_devattr(const char *dir, char *device_name, char *attr,
                   unsigned int *value) {
  char *dev_dir_name;
  int dev_num, ret = 0;
  dev_num = find_type_by_name(device_name, "iio:device");
  if (dev_num < 0) {
    syslog(LOG_INFO, "Failed to find the %s\n", device_name);
    ret = -ENODEV;
    goto error_ret;
  }
  asprintf(&dev_dir_name, "%siio:device%d", dir, dev_num);
  ret = read_sysfs_posint(attr, dev_dir_name);
  if (ret < 0) {
    syslog(LOG_INFO, "read_sysfs_posint failed (%d)\n", 232);
  }
  *value = ret;
  free(dev_dir_name);
error_ret:
  return ret;
}


x86 assembly (clang, -O0):
<__read_devattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <find_type_by_name@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ba <__read_devattr+0x6a>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
xor    %eax,%eax
mov    0x2e30(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x30(%rbp)
jmp    1219 <__read_devattr+0xc9>
mov    -0x8(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    -0x28(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1060 <asprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <read_sysfs_posint@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1207 <__read_devattr+0xb7>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    $0xe8,%edx
mov    $0x0,%al
call   1050 <syslog@plt>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__read_devattr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1070 <find_type_by_name@plt>
test   %eax,%eax
js     11c6 <__read_devattr+0x76>
lea    0xea5(%rip),%rsi
mov    %rsp,%rdi
mov    %rbp,%rdx
mov    %eax,%ecx
call   1060 <asprintf@plt>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1040 <read_sysfs_posint@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b8 <__read_devattr+0x68>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0xe8,%edx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    %ebp,(%r14)
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    11eb <__read_devattr+0x9b>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <syslog@plt>
mov    0x2df7(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"iio:device\00"
@LOG_INFO = global i32 0
@.str.1 = [23 x i8] c"Failed to find the %s\0A\00"
@ENODEV = global i32 0
@.str.2 = [15 x i8] c"%siio:device%d\00"
@.str.3 = [31 x i8] c"read_sysfs_posint failed (%d)\0A\00"
define i32 @__read_devattr(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i32 0, i32* %11
%12 = load i8*, i8** %6
%13 = call i32 @find_type_by_name(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %4
%17 = load i32, i32* @LOG_INFO
%18 = load i8*, i8** %6
%19 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @ENODEV
%21 = sub nsw i32 0, %20
store i32 %21, i32* %11
br label %39
22: ; preds = %4
%23 = load i8*, i8** %5
%24 = load i32, i32* %10
%25 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %24)
%26 = load i8*, i8** %7
%27 = load i8*, i8** %9
%28 = call i32 @read_sysfs_posint(i8* %26, i8* %27)
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* @LOG_INFO
%33 = call i32 (i32, i8*, ...) @syslog(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 232)
br label %34
34: ; preds = %31, %22
%35 = load i32, i32* %11
%36 = load i32*, i32** %8
store i32 %35, i32* %36
%37 = load i8*, i8** %9
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %34, %16
%40 = load i32, i32* %11
ret i32 %40
}

LLVM IR (-O2):
@.str = [11 x i8] c"iio:device\00"
@LOG_INFO = global i32 0
@.str.1 = [23 x i8] c"Failed to find the %s\0A\00"
@ENODEV = global i32 0
@.str.2 = [15 x i8] c"%siio:device%d\00"
@.str.3 = [31 x i8] c"read_sysfs_posint failed (%d)\0A\00"
define i32 @__read_devattr(i8* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = tail call i32 @find_type_by_name(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load i32, i32* @LOG_INFO
%11 = tail call i32 (i32, i8*, ...) @syslog(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = load i32, i32* @ENODEV
%13 = sub nsw i32 0, %12
br label %25
14: ; preds = %4
%15 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %7)
%16 = load i8*, i8** %5
%17 = call i32 @read_sysfs_posint(i8* %2, i8* %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @LOG_INFO
%21 = call i32 (i32, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 232)
br label %22
22: ; preds = %19, %14
store i32 %17, i32* %3
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %9
%26 = phi i32 [ %13, %9 ], [ %17, %22 ]
ret i32 %26
}