#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 *, ...);
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;
      }
    }
    if (ret != sizeof(event)) {
      printf("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     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    145f <main+0x29f>
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    0x2d68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    145f <main+0x29f>
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    0x2d38(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    145f <main+0x29f>
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    0x2d00(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1450 <main+0x290>
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    0x2ca6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c92(%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    1450 <main+0x290>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1384 <main+0x1c4>
xor    %eax,%eax
mov    0x2c4e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    1450 <main+0x290>
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    0x2c1a(%rip),%rax
mov    (%rax),%eax
mov    0x2bf9(%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    0x2bed(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
lea    0xced(%rip),%rdi
call   10c0 <perror@plt>
jmp    142e <main+0x26e>
movslq -0x2c(%rbp),%rax
cmp    $0x4,%rax
je     1420 <main+0x260>
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    0x2bc2(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
jmp    142e <main+0x26e>
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    144b <main+0x28b>
lea    0xcc6(%rip),%rdi
call   10c0 <perror@plt>
jmp    1450 <main+0x290>
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    13cb <main+0x1fb>
mov    0x8(%rsi),%r14
lea    0xe12(%rip),%rsi
mov    %r14,%rdi
call   10f0 <find_type_by_name@plt>
test   %eax,%eax
js     124c <main+0x7c>
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     130e <main+0x13e>
mov    0x10(%rsp),%rdi
jmp    1265 <main+0x95>
mov    %r14,%rdi
call   10e0 <strdup@plt>
mov    %rax,%rdi
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1378 <main+0x1a8>
xor    %esi,%esi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x14c>
mov    %eax,%ebp
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1343 <main+0x173>
cmpl   $0xffffffff,0xc(%rsp)
je     1343 <main+0x173>
mov    %ebp,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     13b6 <main+0x1e6>
lea    0x18(%rsp),%rbp
mov    0x2d0c(%rip),%r15
mov    0x2ced(%rip),%r12
lea    0xe49(%rip),%r14
jmp    12d8 <main+0x108>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1060 <print_event@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1090 <read@plt>
cmp    $0x4,%eax
je     12d0 <main+0x100>
cmp    $0xffffffff,%eax
jne    1385 <main+0x1b5>
mov    (%r15),%ebx
cmp    (%r12),%ebx
jne    13da <main+0x20a>
mov    %r14,%rdi
call   1040 <puts@plt>
jmp    12d8 <main+0x108>
mov    0x2cbb(%rip),%rax
sub    (%rax),%ebx
jmp    13cb <main+0x1fb>
mov    0x2ca5(%rip),%rax
mov    (%rax),%ebx
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xd31(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    13bf <main+0x1ef>
mov    0x2c7e(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    13bf <main+0x1ef>
lea    0xd25(%rip),%rdi
jmp    13af <main+0x1df>
mov    0x2c51(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    13cb <main+0x1fb>
lea    0xd71(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%ebx
mov    0xc(%rsp),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    13bf <main+0x1ef>
lea    0xd33(%rip),%rdi
call   10d0 <perror@plt>
jmp    13bf <main+0x1ef>
mov    0x2c0b(%rip),%rax
mov    (%rax),%ebx
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
lea    0xce0(%rip),%rdi
call   10d0 <perror@plt>
jmp    139a <main+0x1ca>

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 = [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 %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 %124
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 %124
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 %124
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 %120
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 %120
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 %120
87: ; preds = %80
br label %88
88: ; preds = %87, %97, %111
%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 %113
103: ; preds = %88
%104 = load i32, i32* %9
%105 = sext i32 %104 to i64
%106 = icmp ne i64 %105, 4
br i1 %106, label %107, label %111
107: ; preds = %103
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%109 = load i32, i32* @EIO
%110 = sub nsw i32 0, %109
store i32 %110, i32* %9
br label %113
111: ; preds = %103
%112 = call i32 @print_event(%struct.iio_event_data* %6)
br label %88
113: ; preds = %107, %99
%114 = load i32, i32* %12
%115 = call i32 @close(i32 %114)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %119
117: ; preds = %113
%118 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %119
119: ; preds = %117, %113
br label %120
120: ; preds = %119, %84, %79, %54
%121 = load i8*, i8** %8
%122 = call i32 @free(i8* %121)
%123 = load i32, i32* %9
store i32 %123, i32* %3
br label %124
124: ; preds = %120, %45, %36, %15
%125 = load i32, i32* %3
ret i32 %125
}

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"
@EIO = global i32 0
@.str.10 = [27 x i8] c"Failed to close event file\00"
@str = [22 x i8] c"Reading event failed!\00"
@str.11 = [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 %91
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 %91
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 %91
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 %86
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 %86
55: ; preds = %49
%56 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %86
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 %86
62: ; preds = %57, %71
%63 = load i32, i32* %5
%64 = call i32 @read(i32 %63, %struct.iio_event_data* %3, i32 4)
switch i32 %64, label %74 [
i32 -1, label %65
i32 4, label %77
]
65: ; preds = %62
%66 = load i32, i32* @errno
%67 = load i32, i32* @EAGAIN
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
br label %71
71: ; preds = %69, %77
br label %62
72: ; preds = %65
%73 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %79
74: ; preds = %62
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%76 = load i32, i32* @EIO
br label %79
77: ; preds = %62
%78 = call i32 @print_event(%struct.iio_event_data* %3)
br label %71
79: ; preds = %74, %72
%80 = phi i32 [ %66, %72 ], [ %76, %74 ]
%81 = load i32, i32* %5
%82 = call i32 @close(i32 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %86
86: ; preds = %79, %84, %49, %55, %60, %37
%87 = phi i32 [ %38, %37 ], [ %50, %55 ], [ %50, %49 ], [ %61, %60 ], [ %80, %84 ], [ %80, %79 ]
%88 = sub nsw i32 0, %87
%89 = load i8*, i8** %4
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %86, %30, %24, %10
%92 = phi i32 [ -1, %10 ], [ %26, %24 ], [ %88, %86 ], [ %32, %30 ]
ret i32 %92
}