#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 */
struct iio_event_data {
  int dummy;
};
typedef int /*<<< orphan*/ event;

/* Variables and functions */
int EAGAIN;
int EIO;
int ENOMEM;
int /*<<< orphan*/ IIO_GET_EVENT_FD_IOCTL;
int asprintf(char **, char *, int);
int close(int);
int errno;
int find_type_by_name(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_event(struct iio_event_data *);
int /*<<< orphan*/ printf(char *, char const *, int);
int read(int, struct iio_event_data *, int);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int main(int argc, char **argv) {
  struct iio_event_data event;
  const char *device_name;
  char *chrdev_name;
  int ret;
  int dev_num;
  int fd, event_fd;
  if (argc <= 1) {
    fprintf(stderr, "Usage: %s <device_name>\n", argv[0]);
    return -1;
  }
  device_name = argv[1];
  dev_num = find_type_by_name(device_name, "iio:device");
  if (dev_num >= 0) {
    printf("Found IIO device with name %s with device number %d\n", device_name,
           dev_num);
    ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
    if (ret < 0)
      return -ENOMEM;
  } else {
    chrdev_name = strdup(device_name);
    if (!chrdev_name)
      return -ENOMEM;
  }
  fd = open(chrdev_name, 0);
  if (fd == -1) {
    ret = -errno;
    fprintf(stderr, "Failed to open %s\n", chrdev_name);
    goto error_free_chrdev_name;
  }
  ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
  if (ret == -1 || event_fd == -1) {
    ret = -errno;
    fprintf(stderr, "Failed to retrieve event fd\n");
    if (close(fd) == -1)
      perror("Failed to close character device file");
    goto error_free_chrdev_name;
  }
  if (close(fd) == -1) {
    ret = -errno;
    goto error_free_chrdev_name;
  }
  while (true) {
    ret = read(event_fd, &event, sizeof(event));
    if (ret == -1) {
      if (errno == EAGAIN) {
        fprintf(stderr, "nothing available\n");
        continue;
      } else {
        ret = -errno;
        perror("Failed to read event from device");
        break;
      }
    }
    if (ret != sizeof(event)) {
      fprintf(stderr, "Reading event failed!\n");
      ret = -EIO;
      break;
    }
    print_event(&event);
  }
  if (close(event_fd) == -1)
    perror("Failed to close event file");
error_free_chrdev_name:
  free(chrdev_name);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     120a <main+0x4a>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1478 <main+0x2b8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10e0 <find_type_by_name@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     127e <main+0xbe>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   10a0 <asprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1279 <main+0xb9>
xor    %eax,%eax
mov    0x2d61(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1478 <main+0x2b8>
jmp    12ae <main+0xee>
mov    -0x20(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12a9 <main+0xe9>
xor    %eax,%eax
mov    0x2d31(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1478 <main+0x2b8>
jmp    12ae <main+0xee>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   10b0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    12f4 <main+0x134>
xor    %eax,%eax
mov    0x2cf1(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1469 <main+0x2a9>
mov    -0x34(%rbp),%edi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     1320 <main+0x160>
cmpl   $0xffffffff,-0x38(%rbp)
jne    1367 <main+0x1a7>
xor    %eax,%eax
mov    0x2c97(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1362 <main+0x1a2>
lea    0xd3e(%rip),%rdi
call   10c0 <perror@plt>
jmp    1469 <main+0x2a9>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    138b <main+0x1cb>
xor    %eax,%eax
mov    0x2c3f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    1469 <main+0x2a9>
jmp    1390 <main+0x1d0>
mov    -0x38(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1401 <main+0x241>
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
mov    0x2bf2(%rip),%rcx
cmp    (%rcx),%eax
jne    13e2 <main+0x222>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1390 <main+0x1d0>
xor    %eax,%eax
mov    0x2bd5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
lea    0xcdd(%rip),%rdi
call   10c0 <perror@plt>
jmp    1447 <main+0x287>
movslq -0x2c(%rbp),%rax
cmp    $0x4,%rax
je     1439 <main+0x279>
mov    0x2bb2(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %eax,%eax
mov    0x2ba9(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    1447 <main+0x287>
lea    -0x18(%rbp),%rdi
call   1050 <print_event@plt>
jmp    1390 <main+0x1d0>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1464 <main+0x2a4>
lea    0xcad(%rip),%rdi
call   10c0 <perror@plt>
jmp    1469 <main+0x2a9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     11f7 <main+0x37>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    13cc <main+0x20c>
mov    0x8(%rsi),%rbx
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <find_type_by_name@plt>
test   %eax,%eax
js     1243 <main+0x83>
mov    %eax,%ebp
lea    0xe0d(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
lea    0xe31(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %ebp,%edx
call   10a0 <asprintf@plt>
test   %eax,%eax
js     1314 <main+0x154>
mov    0x8(%rsp),%rdi
jmp    125c <main+0x9c>
mov    %rbx,%rdi
call   10d0 <strdup@plt>
mov    %rax,%rdi
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1314 <main+0x154>
xor    %esi,%esi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1324 <main+0x164>
mov    %eax,%ebp
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     134b <main+0x18b>
cmpl   $0xffffffff,0x4(%rsp)
je     134b <main+0x18b>
mov    %ebp,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     13b7 <main+0x1f7>
lea    0x10(%rsp),%r14
mov    0x2d0d(%rip),%r15
mov    0x2cf6(%rip),%r13
mov    0x2d07(%rip),%r12
lea    0xdf9(%rip),%rbp
jmp    12d8 <main+0x118>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <print_event@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
cmp    $0x4,%eax
je     12d0 <main+0x110>
cmp    $0xffffffff,%eax
jne    1380 <main+0x1c0>
mov    (%r15),%ebx
cmp    0x0(%r13),%ebx
jne    13dd <main+0x21d>
mov    (%r12),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12d8 <main+0x118>
mov    0x2cb5(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    13cc <main+0x20c>
mov    0x2c95(%rip),%rax
mov    (%rax),%ebx
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xd29(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    13c0 <main+0x200>
mov    0x2c6e(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    13c0 <main+0x200>
lea    0xd1d(%rip),%rdi
jmp    13b0 <main+0x1f0>
mov    (%r12),%edi
lea    0xd6a(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%ebx
mov    0x4(%rsp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    13c0 <main+0x200>
lea    0xd5c(%rip),%rdi
call   10c0 <perror@plt>
jmp    13c0 <main+0x200>
mov    0x2c02(%rip),%rax
mov    (%rax),%ebx
neg    %ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf0(%rip),%rdi
call   10c0 <perror@plt>
jmp    139b <main+0x1db>

LLVM IR (-O0):
%struct.iio_event_data = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <device_name>\0A\00"
@.str.1 = [11 x i8] c"iio:device\00"
@.str.2 = [53 x i8] c"Found IIO device with name %s with device number %d\0A\00"
@.str.3 = [18 x i8] c"/dev/iio:device%d\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.4 = [19 x i8] c"Failed to open %s\0A\00"
@IIO_GET_EVENT_FD_IOCTL = global i32 0
@.str.5 = [29 x i8] c"Failed to retrieve event fd\0A\00"
@.str.6 = [38 x i8] c"Failed to close character device file\00"
@EAGAIN = global i32 0
@.str.7 = [19 x i8] c"nothing available\0A\00"
@.str.8 = [33 x i8] c"Failed to read event from device\00"
@.str.9 = [23 x i8] c"Reading event failed!\0A\00"
@EIO = global i32 0
@.str.10 = [27 x i8] c"Failed to close event file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.iio_event_data
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sle i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %127
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = call i32 @find_type_by_name(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %21
%30 = load i8*, i8** %7
%31 = load i32, i32* %10
%32 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 %31)
%33 = load i32, i32* %10
%34 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = load i32, i32* @ENOMEM
%39 = sub nsw i32 0, %38
store i32 %39, i32* %3
br label %127
40: ; preds = %29
br label %50
41: ; preds = %21
%42 = load i8*, i8** %7
%43 = call i8* @strdup(i8* %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %49, label %46
46: ; preds = %41
%47 = load i32, i32* @ENOMEM
%48 = sub nsw i32 0, %47
store i32 %48, i32* %3
br label %127
49: ; preds = %41
br label %50
50: ; preds = %49, %40
%51 = load i8*, i8** %8
%52 = call i32 @open(i8* %51, i32 0)
store i32 %52, i32* %11
%53 = load i32, i32* %11
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %50
%56 = load i32, i32* @errno
%57 = sub nsw i32 0, %56
store i32 %57, i32* %9
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %8
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %123
61: ; preds = %50
%62 = load i32, i32* %11
%63 = load i32, i32* @IIO_GET_EVENT_FD_IOCTL
%64 = call i32 @ioctl(i32 %62, i32 %63, i32* %12)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, -1
br i1 %66, label %70, label %67
67: ; preds = %61
%68 = load i32, i32* %12
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %81
70: ; preds = %67, %61
%71 = load i32, i32* @errno
%72 = sub nsw i32 0, %71
store i32 %72, i32* %9
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%75 = load i32, i32* %11
%76 = call i32 @close(i32 %75)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %80
78: ; preds = %70
%79 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %80
80: ; preds = %78, %70
br label %123
81: ; preds = %67
%82 = load i32, i32* %11
%83 = call i32 @close(i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i32, i32* @errno
%87 = sub nsw i32 0, %86
store i32 %87, i32* %9
br label %123
88: ; preds = %81
br label %89
89: ; preds = %88, %98, %114
%90 = load i32, i32* %12
%91 = call i32 @read(i32 %90, %struct.iio_event_data* %6, i32 4)
store i32 %91, i32* %9
%92 = load i32, i32* %9
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %105
94: ; preds = %89
%95 = load i32, i32* @errno
%96 = load i32, i32* @EAGAIN
%97 = icmp eq i32 %95, %96
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %89
101: ; preds = %94
%102 = load i32, i32* @errno
%103 = sub nsw i32 0, %102
store i32 %103, i32* %9
%104 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %116
105: ; preds = %89
%106 = load i32, i32* %9
%107 = sext i32 %106 to i64
%108 = icmp ne i64 %107, 4
br i1 %108, label %109, label %114
109: ; preds = %105
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%112 = load i32, i32* @EIO
%113 = sub nsw i32 0, %112
store i32 %113, i32* %9
br label %116
114: ; preds = %105
%115 = call i32 @print_event(%struct.iio_event_data* %6)
br label %89
116: ; preds = %109, %101
%117 = load i32, i32* %12
%118 = call i32 @close(i32 %117)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %122
120: ; preds = %116
%121 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %122
122: ; preds = %120, %116
br label %123
123: ; preds = %122, %85, %80, %55
%124 = load i8*, i8** %8
%125 = call i32 @free(i8* %124)
%126 = load i32, i32* %9
store i32 %126, i32* %3
br label %127
127: ; preds = %123, %46, %37, %15
%128 = load i32, i32* %3
ret i32 %128
}

LLVM IR (-O2):
%struct.iio_event_data = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <device_name>\0A\00"
@.str.1 = [11 x i8] c"iio:device\00"
@.str.2 = [53 x i8] c"Found IIO device with name %s with device number %d\0A\00"
@.str.3 = [18 x i8] c"/dev/iio:device%d\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.4 = [19 x i8] c"Failed to open %s\0A\00"
@IIO_GET_EVENT_FD_IOCTL = global i32 0
@.str.5 = [29 x i8] c"Failed to retrieve event fd\0A\00"
@.str.6 = [38 x i8] c"Failed to close character device file\00"
@EAGAIN = global i32 0
@.str.7 = [19 x i8] c"nothing available\0A\00"
@.str.8 = [33 x i8] c"Failed to read event from device\00"
@.str.9 = [23 x i8] c"Reading event failed!\0A\00"
@EIO = global i32 0
@.str.10 = [27 x i8] c"Failed to close event file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.iio_event_data
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast %struct.iio_event_data* %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %94
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @find_type_by_name(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp sgt i32 %17, -1
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 %17)
%21 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%22 = icmp slt i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load i8*, i8** %4
br label %34
25: ; preds = %19
%26 = load i32, i32* @ENOMEM
%27 = sub nsw i32 0, %26
br label %94
28: ; preds = %14
%29 = tail call i8* @strdup(i8* %16)
store i8* %29, i8** %4
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @ENOMEM
%33 = sub nsw i32 0, %32
br label %94
34: ; preds = %23, %28
%35 = phi i8* [ %24, %23 ], [ %29, %28 ]
%36 = call i32 @open(i8* %35, i32 0)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32, i32* @errno
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %4
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %89
43: ; preds = %34
%44 = load i32, i32* @IIO_GET_EVENT_FD_IOCTL
%45 = call i32 @ioctl(i32 %36, i32 %44, i32* %5)
%46 = icmp eq i32 %45, -1
%47 = load i32, i32* %5
%48 = icmp eq i32 %47, -1
%49 = select i1 %46, i1 true, i1 %48
br i1 %49, label %50, label %58
50: ; preds = %43
%51 = load i32, i32* @errno
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @close(i32 %36)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %89
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %89
58: ; preds = %43
%59 = call i32 @close(i32 %36)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = load i32, i32* @errno
br label %89
63: ; preds = %58, %73
%64 = load i32, i32* %5
%65 = call i32 @read(i32 %64, %struct.iio_event_data* %3, i32 4)
switch i32 %65, label %76 [
i32 -1, label %66
i32 4, label %80
]
66: ; preds = %63
%67 = load i32, i32* @errno
%68 = load i32, i32* @EAGAIN
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %70, %80
br label %63
74: ; preds = %66
%75 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %82
76: ; preds = %63
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%79 = load i32, i32* @EIO
br label %82
80: ; preds = %63
%81 = call i32 @print_event(%struct.iio_event_data* %3)
br label %73
82: ; preds = %76, %74
%83 = phi i32 [ %67, %74 ], [ %79, %76 ]
%84 = load i32, i32* %5
%85 = call i32 @close(i32 %84)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %82
%88 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %89
89: ; preds = %82, %87, %50, %56, %61, %38
%90 = phi i32 [ %39, %38 ], [ %51, %56 ], [ %51, %50 ], [ %62, %61 ], [ %83, %87 ], [ %83, %82 ]
%91 = sub nsw i32 0, %90
%92 = load i8*, i8** %4
%93 = call i32 @free(i8* %92)
br label %94
94: ; preds = %89, %31, %25, %10
%95 = phi i32 [ -1, %10 ], [ %27, %25 ], [ %91, %89 ], [ %33, %31 ]
ret i32 %95
}