#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 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 *, ...);
int read(int, struct iio_event_data *, int);
int /*<<< orphan*/ stdout;
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) {
    printf("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(stdout, "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(stdout, "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) {
        printf("nothing available\n");
        continue;
      } else {
        ret = -errno;
        perror("Failed to read event from device");
        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     1201 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1430 <main+0x270>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   10e0 <find_type_by_name@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     1277 <main+0xb7>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   10a0 <asprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1272 <main+0xb2>
xor    %eax,%eax
mov    0x2d70(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1430 <main+0x270>
jmp    12a7 <main+0xe7>
mov    -0x20(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12a2 <main+0xe2>
xor    %eax,%eax
mov    0x2d40(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1430 <main+0x270>
jmp    12a7 <main+0xe7>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   10b0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    12ed <main+0x12d>
xor    %eax,%eax
mov    0x2d08(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1421 <main+0x261>
mov    -0x34(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     1319 <main+0x159>
cmpl   $0xffffffff,-0x38(%rbp)
jne    1360 <main+0x1a0>
xor    %eax,%eax
mov    0x2cae(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    135b <main+0x19b>
lea    0xd45(%rip),%rdi
call   10c0 <perror@plt>
jmp    1421 <main+0x261>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1384 <main+0x1c4>
xor    %eax,%eax
mov    0x2c56(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    1421 <main+0x261>
jmp    1389 <main+0x1c9>
mov    -0x38(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13f1 <main+0x231>
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
mov    0x2c01(%rip),%rcx
cmp    (%rcx),%eax
jne    13d2 <main+0x212>
lea    0xcfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1389 <main+0x1c9>
xor    %eax,%eax
mov    0x2bf5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
lea    0xced(%rip),%rdi
call   10c0 <perror@plt>
jmp    13ff <main+0x23f>
lea    -0x18(%rbp),%rdi
call   1050 <print_event@plt>
jmp    1389 <main+0x1c9>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    141c <main+0x25c>
lea    0xcde(%rip),%rdi
call   10c0 <perror@plt>
jmp    1421 <main+0x261>
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   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jg     11fc <main+0x2c>
mov    (%rsi),%rsi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1319 <main+0x149>
mov    0x8(%rsi),%r14
lea    0xe12(%rip),%rsi
mov    %r14,%rdi
call   10f0 <find_type_by_name@plt>
test   %eax,%eax
js     1248 <main+0x78>
mov    %eax,%ebp
lea    0xe08(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %ebp,%edx
call   10b0 <asprintf@plt>
test   %eax,%eax
js     12ab <main+0xdb>
mov    0x10(%rsp),%rdi
jmp    1261 <main+0x91>
mov    %r14,%rdi
call   10e0 <strdup@plt>
mov    %rax,%rdi
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1328 <main+0x158>
xor    %esi,%esi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     12b6 <main+0xe6>
mov    %eax,%ebp
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12dd <main+0x10d>
cmpl   $0xffffffff,0xc(%rsp)
je     12dd <main+0x10d>
mov    %ebp,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    1335 <main+0x165>
mov    0x2d29(%rip),%rax
mov    (%rax),%ebx
jmp    130d <main+0x13d>
mov    0x2d26(%rip),%rax
sub    (%rax),%ebx
jmp    1319 <main+0x149>
mov    0x2d13(%rip),%rax
mov    (%rax),%ebx
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    130d <main+0x13d>
mov    0x2cec(%rip),%rax
mov    (%rax),%ebx
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     1391 <main+0x1c1>
neg    %ebx
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca9(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    1319 <main+0x149>
lea    0x18(%rsp),%rbp
mov    0x2c8f(%rip),%r15
mov    0x2c70(%rip),%r12
lea    0xdae(%rip),%r14
jmp    1368 <main+0x198>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1060 <print_event@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
jne    1360 <main+0x190>
mov    (%r15),%ebx
cmp    (%r12),%ebx
jne    13a2 <main+0x1d2>
mov    %r14,%rdi
call   1040 <puts@plt>
jmp    1368 <main+0x198>
lea    0xd03(%rip),%rdi
call   10d0 <perror@plt>
jmp    130d <main+0x13d>
lea    0xd18(%rip),%rdi
call   10d0 <perror@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    130d <main+0x13d>
lea    0xd1b(%rip),%rdi
jmp    1398 <main+0x1c8>

LLVM IR (-O0):
%struct.iio_event_data = type { i32 }
@.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
@stdout = 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 = [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 %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %116
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = call i32 @find_type_by_name(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %20
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %30)
%32 = load i32, i32* %10
%33 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %32)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* @ENOMEM
%38 = sub nsw i32 0, %37
store i32 %38, i32* %3
br label %116
39: ; preds = %28
br label %49
40: ; preds = %20
%41 = load i8*, i8** %7
%42 = call i8* @strdup(i8* %41)
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = load i32, i32* @ENOMEM
%47 = sub nsw i32 0, %46
store i32 %47, i32* %3
br label %116
48: ; preds = %40
br label %49
49: ; preds = %48, %39
%50 = load i8*, i8** %8
%51 = call i32 @open(i8* %50, i32 0)
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i32, i32* @errno
%56 = sub nsw i32 0, %55
store i32 %56, i32* %9
%57 = load i32, i32* @stdout
%58 = load i8*, i8** %8
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %58)
br label %112
60: ; preds = %49
%61 = load i32, i32* %11
%62 = load i32, i32* @IIO_GET_EVENT_FD_IOCTL
%63 = call i32 @ioctl(i32 %61, i32 %62, i32* %12)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp eq i32 %64, -1
br i1 %65, label %69, label %66
66: ; preds = %60
%67 = load i32, i32* %12
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %80
69: ; preds = %66, %60
%70 = load i32, i32* @errno
%71 = sub nsw i32 0, %70
store i32 %71, i32* %9
%72 = load i32, i32* @stdout
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%74 = load i32, i32* %11
%75 = call i32 @close(i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %79
77: ; preds = %69
%78 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %79
79: ; preds = %77, %69
br label %112
80: ; preds = %66
%81 = load i32, i32* %11
%82 = call i32 @close(i32 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = load i32, i32* @errno
%86 = sub nsw i32 0, %85
store i32 %86, i32* %9
br label %112
87: ; preds = %80
br label %88
88: ; preds = %87, %97, %103
%89 = load i32, i32* %12
%90 = call i32 @read(i32 %89, %struct.iio_event_data* %6, i32 4)
store i32 %90, i32* %9
%91 = load i32, i32* %9
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %103
93: ; preds = %88
%94 = load i32, i32* @errno
%95 = load i32, i32* @EAGAIN
%96 = icmp eq i32 %94, %95
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %88
99: ; preds = %93
%100 = load i32, i32* @errno
%101 = sub nsw i32 0, %100
store i32 %101, i32* %9
%102 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %105
103: ; preds = %88
%104 = call i32 @print_event(%struct.iio_event_data* %6)
br label %88
105: ; preds = %99
%106 = load i32, i32* %12
%107 = call i32 @close(i32 %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %111
109: ; preds = %105
%110 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %111
111: ; preds = %109, %105
br label %112
112: ; preds = %111, %84, %79, %54
%113 = load i8*, i8** %8
%114 = call i32 @free(i8* %113)
%115 = load i32, i32* %9
store i32 %115, i32* %3
br label %116
116: ; preds = %112, %45, %36, %15
%117 = load i32, i32* %3
ret i32 %117
}

LLVM IR (-O2):
%struct.iio_event_data = type { i32 }
@.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
@stdout = 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.8 = [33 x i8] c"Failed to read event from device\00"
@.str.9 = [27 x i8] c"Failed to close event file\00"
@str = [18 x i8] c"nothing available\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 %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %87
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @find_type_by_name(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %16)
%20 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%21 = icmp slt i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = load i8*, i8** %4
br label %33
24: ; preds = %18
%25 = load i32, i32* @ENOMEM
%26 = sub nsw i32 0, %25
br label %87
27: ; preds = %13
%28 = tail call i8* @strdup(i8* %15)
store i8* %28, i8** %4
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @ENOMEM
%32 = sub nsw i32 0, %31
br label %87
33: ; preds = %22, %27
%34 = phi i8* [ %23, %22 ], [ %28, %27 ]
%35 = call i32 @open(i8* %34, i32 0)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* @errno
%39 = load i32, i32* @stdout
%40 = load i8*, i8** %4
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %82
42: ; preds = %33
%43 = load i32, i32* @IIO_GET_EVENT_FD_IOCTL
%44 = call i32 @ioctl(i32 %35, i32 %43, i32* %5)
%45 = icmp eq i32 %44, -1
%46 = load i32, i32* %5
%47 = icmp eq i32 %46, -1
%48 = select i1 %45, i1 true, i1 %47
br i1 %48, label %49, label %57
49: ; preds = %42
%50 = load i32, i32* @errno
%51 = load i32, i32* @stdout
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @close(i32 %35)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %82
55: ; preds = %49
%56 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %82
57: ; preds = %42
%58 = call i32 @close(i32 %35)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = load i32, i32* @errno
br label %82
62: ; preds = %57, %72
%63 = load i32, i32* %5
%64 = call i32 @read(i32 %63, %struct.iio_event_data* %3, i32 4)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %78
66: ; preds = %62
%67 = load i32, i32* @errno
%68 = load i32, i32* @EAGAIN
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %72
72: ; preds = %70, %78
br label %62
73: ; preds = %66
%74 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
%75 = load i32, i32* %5
%76 = call i32 @close(i32 %75)
%77 = icmp eq i32 %76, -1
br i1 %77, label %80, label %82
78: ; preds = %62
%79 = call i32 @print_event(%struct.iio_event_data* %3)
br label %72
80: ; preds = %73
%81 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %82
82: ; preds = %73, %80, %49, %55, %60, %37
%83 = phi i32 [ %38, %37 ], [ %50, %55 ], [ %50, %49 ], [ %61, %60 ], [ %67, %80 ], [ %67, %73 ]
%84 = sub nsw i32 0, %83
%85 = load i8*, i8** %4
%86 = call i32 @free(i8* %85)
br label %87
87: ; preds = %82, %30, %24, %10
%88 = phi i32 [ -1, %10 ], [ %26, %24 ], [ %84, %82 ], [ %32, %30 ]
ret i32 %88
}