#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 */
typedef unsigned long long uint64_t;
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int EIO;
int ENOENT;
int ENOMEM;
int asprintf(char **, char *, char const *, ...);
int closedir(int /*<<< orphan*/ *);
int errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, unsigned int *,
           unsigned int *, unsigned int *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
                      unsigned *shift, uint64_t *mask, unsigned *be,
                      const char *device_dir, const char *name,
                      const char *generic_name) {
  FILE *sysfsfp;
  int ret;
  DIR *dp;
  char *scan_el_dir, *builtname, *builtname_generic, *filename = 0;
  char signchar, endianchar;
  unsigned padint;
  const struct dirent *ent;
  ret = asprintf(&scan_el_dir, "%s/scan_elements", device_dir);
  if (ret < 0) {
    return -ENOMEM;
  }
  ret = asprintf(&builtname, "%s_type", name);
  if (ret < 0) {
    ret = -ENOMEM;
    goto error_free_scan_el_dir;
  }
  ret = asprintf(&builtname_generic, "%s_type", generic_name);
  if (ret < 0) {
    ret = -ENOMEM;
    goto error_free_builtname;
  }
  dp = opendir(scan_el_dir);
  if (!dp) {
    ret = -errno;
    goto error_free_builtname_generic;
  }
  ret = -ENOENT;
  while (ent = readdir(dp), ent)
    if ((strcmp(builtname, ent->d_name) == 0) ||
        (strcmp(builtname_generic, ent->d_name) == 0)) {
      ret = asprintf(&filename, "%s/%s", scan_el_dir, ent->d_name);
      if (ret < 0) {
        ret = -ENOMEM;
        goto error_closedir;
      }
      sysfsfp = fopen(filename, "r");
      if (!sysfsfp) {
        ret = -errno;
        fprintf(stderr, "failed to open %s\n", filename);
        goto error_free_filename;
      }
      ret = fscanf(sysfsfp, "%ce:%c%u/%u>>%u", &endianchar, &signchar,
                   bits_used, &padint, shift);
      if (ret < 0) {
        ret = -errno;
        fprintf(stderr, "failed to pass scan type description\n");
        goto error_close_sysfsfp;
      } else if (ret != 5) {
        ret = -EIO;
        fprintf(stderr, "scan type description didn't match\n");
        goto error_close_sysfsfp;
      }
      *be = (endianchar == 'b');
      *bytes = padint / 8;
      if (*bits_used == 64) {
        *mask = ~0;
      } else {
        *mask = (1ULL << *bits_used) - 1;
      }
      *is_signed = (signchar == 's');
      if (fclose(sysfsfp)) {
        ret = -errno;
        fprintf(stderr, "Failed to close %s\n", filename);
        goto error_free_filename;
      }
      sysfsfp = 0;
      free(filename);
      filename = 0;
      if (strcmp(builtname, ent->d_name) == 0) {
        break;
      }
    }
error_close_sysfsfp:
  if (sysfsfp)
    if (fclose(sysfsfp)) {
      perror("iioutils_get_type(): Failed to close file");
    }
error_free_filename:
  if (filename) {
    free(filename);
  }
error_closedir:
  if (closedir(dp) == -1) {
    perror("iioutils_get_type(): Failed to close directory");
  }
error_free_builtname_generic:
  free(builtname_generic);
error_free_builtname:
  free(builtname);
error_free_scan_el_dir:
  free(scan_el_dir);
  return ret;
}


x86 assembly (clang, -O0):
<iioutils_get_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x70(%rbp)
mov    0x10(%rbp),%rdx
lea    -0x58(%rbp),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    121d <iioutils_get_type+0x6d>
xor    %eax,%eax
mov    0x2dc5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    15b6 <iioutils_get_type+0x406>
mov    0x18(%rbp),%rdx
lea    -0x60(%rbp),%rdi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1253 <iioutils_get_type+0xa3>
xor    %eax,%eax
mov    0x2d8f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    15a7 <iioutils_get_type+0x3f7>
mov    0x20(%rbp),%rdx
lea    -0x68(%rbp),%rdi
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1289 <iioutils_get_type+0xd9>
xor    %eax,%eax
mov    0x2d59(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    159e <iioutils_get_type+0x3ee>
mov    -0x58(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12b4 <iioutils_get_type+0x104>
xor    %eax,%eax
mov    0x2d1e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    1595 <iioutils_get_type+0x3e5>
xor    %eax,%eax
mov    0x2cfb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    -0x50(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     1520 <iioutils_get_type+0x370>
mov    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     130c <iioutils_get_type+0x15c>
mov    -0x68(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    151b <iioutils_get_type+0x36b>
mov    -0x58(%rbp),%rdx
mov    -0x80(%rbp),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%rdi
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1348 <iioutils_get_type+0x198>
xor    %eax,%eax
mov    0x2c9a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    1572 <iioutils_get_type+0x3c2>
mov    -0x70(%rbp),%rdi
lea    0xccc(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1395 <iioutils_get_type+0x1e5>
xor    %eax,%eax
mov    0x2c58(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rdx
lea    0xc98(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1559 <iioutils_get_type+0x3a9>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%rax
lea    0xc8c(%rip),%rsi
lea    -0x72(%rbp),%rdx
lea    -0x71(%rbp),%rcx
lea    -0x78(%rbp),%r9
mov    %rax,(%rsp)
call   1060 <fscanf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    13f4 <iioutils_get_type+0x244>
xor    %eax,%eax
mov    0x2bf5(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
lea    0xc5c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1525 <iioutils_get_type+0x375>
cmpl   $0x5,-0x44(%rbp)
je     1428 <iioutils_get_type+0x278>
xor    %eax,%eax
mov    0x2bd9(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1525 <iioutils_get_type+0x375>
jmp    142d <iioutils_get_type+0x27d>
movsbl -0x72(%rbp),%eax
cmp    $0x62,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x78(%rbp),%ecx
shr    $0x3,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x40,(%rax)
jne    146b <iioutils_get_type+0x2bb>
mov    -0x30(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
jmp    1489 <iioutils_get_type+0x2d9>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,%rcx
sub    $0x1,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movsbl -0x71(%rbp),%eax
cmp    $0x73,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     14df <iioutils_get_type+0x32f>
xor    %eax,%eax
mov    0x2b0e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b0a(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rdx
lea    0xbbb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1559 <iioutils_get_type+0x3a9>
movq   $0x0,-0x40(%rbp)
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x70(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1516 <iioutils_get_type+0x366>
jmp    1520 <iioutils_get_type+0x370>
jmp    151b <iioutils_get_type+0x36b>
jmp    12c2 <iioutils_get_type+0x112>
jmp    1525 <iioutils_get_type+0x375>
cmpq   $0x0,-0x40(%rbp)
je     1554 <iioutils_get_type+0x3a4>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     154f <iioutils_get_type+0x39f>
lea    0xb58(%rip),%rdi
call   10d0 <perror@plt>
jmp    1554 <iioutils_get_type+0x3a4>
jmp    1559 <iioutils_get_type+0x3a9>
cmpq   $0x0,-0x70(%rbp)
je     156d <iioutils_get_type+0x3bd>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
jmp    1572 <iioutils_get_type+0x3c2>
mov    -0x50(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
jne    1590 <iioutils_get_type+0x3e0>
lea    0xb41(%rip),%rdi
call   10d0 <perror@plt>
jmp    1595 <iioutils_get_type+0x3e5>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iioutils_get_type>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,%r14
mov    %r8,%r12
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,0x50(%rsp)
mov    0x90(%rsp),%rdx
movq   $0x0,0x10(%rsp)
lea    0xe16(%rip),%rsi
xor    %ebp,%ebp
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13dc <iioutils_get_type+0x22c>
mov    0x98(%rsp),%rdx
lea    0xe02(%rip),%rsi
xor    %ebp,%ebp
lea    0x18(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13ea <iioutils_get_type+0x23a>
mov    0xa0(%rsp),%rdx
lea    0xddd(%rip),%rsi
xor    %ebp,%ebp
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13f8 <iioutils_get_type+0x248>
mov    %rbx,0x48(%rsp)
mov    0x20(%rsp),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1406 <iioutils_get_type+0x256>
mov    %rax,%rbx
mov    %r12,0x38(%rsp)
mov    %r14,0x40(%rsp)
mov    0x2d42(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     14bc <iioutils_get_type+0x30c>
mov    %rax,%r12
jmp    12a4 <iioutils_get_type+0xf4>
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     14bc <iioutils_get_type+0x30c>
mov    0x18(%rsp),%rdi
mov    (%r12),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12ca <iioutils_get_type+0x11a>
mov    0x30(%rsp),%rdi
mov    (%r12),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1290 <iioutils_get_type+0xe0>
mov    0x20(%rsp),%rdx
mov    (%r12),%ecx
lea    0x10(%rsp),%rdi
lea    0xd3a(%rip),%rsi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     1416 <iioutils_get_type+0x266>
mov    0x10(%rsp),%rdi
lea    0xd25(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1426 <iioutils_get_type+0x276>
mov    %rax,%r14
mov    %r13,(%rsp)
mov    %rax,%rdi
lea    0xd1b(%rip),%rsi
lea    0xe(%rsp),%rdx
lea    0xf(%rsp),%rcx
mov    %r15,%r8
lea    0x2c(%rsp),%r9
call   1060 <fscanf@plt>
test   %eax,%eax
js     1448 <iioutils_get_type+0x298>
cmp    $0x5,%eax
jne    1458 <iioutils_get_type+0x2a8>
xor    %eax,%eax
cmpb   $0x62,0xe(%rsp)
sete   %al
mov    0x40(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x2c(%rsp),%eax
shr    $0x3,%eax
mov    0x48(%rsp),%rcx
mov    %eax,(%rcx)
mov    (%r15),%ecx
mov    $0xffffffffffffffff,%rax
shl    %cl,%rax
cmp    $0x40,%ecx
not    %rax
mov    $0xffffffffffffffff,%rcx
cmove  %rcx,%rax
mov    0x38(%rsp),%rcx
mov    %rax,(%rcx)
xor    %eax,%eax
cmpb   $0x73,0xf(%rsp)
sete   %al
mov    0x50(%rsp),%rcx
mov    %eax,(%rcx)
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1495 <iioutils_get_type+0x2e5>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,0x10(%rsp)
mov    0x18(%rsp),%rdi
mov    (%r12),%esi
call   1080 <strcmp@plt>
mov    $0x5,%ebp
test   %rax,%rax
jne    1290 <iioutils_get_type+0xe0>
jmp    14bc <iioutils_get_type+0x30c>
mov    0x2bf5(%rip),%rax
sub    (%rax),%ebp
jmp    14f6 <iioutils_get_type+0x346>
mov    0x2be7(%rip),%rax
sub    (%rax),%ebp
jmp    14ec <iioutils_get_type+0x33c>
mov    0x2bd9(%rip),%rax
sub    (%rax),%ebp
jmp    14e2 <iioutils_get_type+0x332>
mov    0x2bbb(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14d8 <iioutils_get_type+0x328>
mov    0x2bbb(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14cb <iioutils_get_type+0x31b>
mov    0x2b9b(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xbdb(%rip),%rsi
jmp    14b5 <iioutils_get_type+0x305>
lea    0xbf5(%rip),%rsi
mov    0x2b72(%rip),%rcx
jmp    1466 <iioutils_get_type+0x2b6>
mov    0x2b81(%rip),%rcx
lea    0xc04(%rip),%rsi
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
sub    (%rcx),%ebp
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     14bc <iioutils_get_type+0x30c>
lea    0xc14(%rip),%rdi
call   10d0 <perror@plt>
jmp    14bc <iioutils_get_type+0x30c>
mov    0x2b2c(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xbd9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     14cb <iioutils_get_type+0x31b>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
je     1507 <iioutils_get_type+0x357>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbbe(%rip),%rdi
call   10d0 <perror@plt>
jmp    14d8 <iioutils_get_type+0x328>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [17 x i8] c"%s/scan_elements\00"
@ENOMEM = global i32 0
@.str.1 = [8 x i8] c"%s_type\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [19 x i8] c"failed to open %s\0A\00"
@.str.5 = [16 x i8] c"%ce:%c%u/%u>>%u\00"
@.str.6 = [38 x i8] c"failed to pass scan type description\0A\00"
@EIO = global i32 0
@.str.7 = [36 x i8] c"scan type description didn't match\0A\00"
@.str.8 = [20 x i8] c"Failed to close %s\0A\00"
@.str.9 = [42 x i8] c"iioutils_get_type(): Failed to close file\00"
@.str.10 = [47 x i8] c"iioutils_get_type(): Failed to close directory\00"
define i32 @iioutils_get_type(i32* %0, i32* %1, i32* %2, i32* %3, i64* %4, i32* %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i64*
%16 = alloca i32*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32*
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i8*
%24 = alloca i8*
%25 = alloca i8*
%26 = alloca i8*
%27 = alloca i8
%28 = alloca i8
%29 = alloca i32
%30 = alloca %struct.dirent*
store i32* %0, i32** %11
store i32* %1, i32** %12
store i32* %2, i32** %13
store i32* %3, i32** %14
store i64* %4, i64** %15
store i32* %5, i32** %16
store i8* %6, i8** %17
store i8* %7, i8** %18
store i8* %8, i8** %19
store i8* null, i8** %26
%31 = load i8*, i8** %17
%32 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 %32, i32* %21
%33 = load i32, i32* %21
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %9
%36 = load i32, i32* @ENOMEM
%37 = sub nsw i32 0, %36
store i32 %37, i32* %10
br label %211
38: ; preds = %9
%39 = load i8*, i8** %18
%40 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %39)
store i32 %40, i32* %21
%41 = load i32, i32* %21
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32, i32* @ENOMEM
%45 = sub nsw i32 0, %44
store i32 %45, i32* %21
br label %207
46: ; preds = %38
%47 = load i8*, i8** %19
%48 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %47)
store i32 %48, i32* %21
%49 = load i32, i32* %21
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i32, i32* @ENOMEM
%53 = sub nsw i32 0, %52
store i32 %53, i32* %21
br label %204
54: ; preds = %46
%55 = load i8*, i8** %23
%56 = call i32* @opendir(i8* %55)
store i32* %56, i32** %22
%57 = load i32*, i32** %22
%58 = icmp ne i32* %57, null
br i1 %58, label %62, label %59
59: ; preds = %54
%60 = load i32, i32* @errno
%61 = sub nsw i32 0, %60
store i32 %61, i32* %21
br label %201
62: ; preds = %54
%63 = load i32, i32* @ENOENT
%64 = sub nsw i32 0, %63
store i32 %64, i32* %21
br label %65
65: ; preds = %174, %62
%66 = load i32*, i32** %22
%67 = call %struct.dirent* @readdir(i32* %66)
store %struct.dirent* %67, %struct.dirent** %30
%68 = load %struct.dirent*, %struct.dirent** %30
%69 = icmp ne %struct.dirent* %68, null
br i1 %69, label %70, label %175
70: ; preds = %65
%71 = load i8*, i8** %24
%72 = load %struct.dirent*, %struct.dirent** %30
%73 = getelementptr inbounds %struct.dirent, %struct.dirent* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i64 @strcmp(i8* %71, i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %84, label %77
77: ; preds = %70
%78 = load i8*, i8** %25
%79 = load %struct.dirent*, %struct.dirent** %30
%80 = getelementptr inbounds %struct.dirent, %struct.dirent* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i64 @strcmp(i8* %78, i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %174
84: ; preds = %77, %70
%85 = load i8*, i8** %23
%86 = load %struct.dirent*, %struct.dirent** %30
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %86, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %85, i32 %88)
store i32 %89, i32* %21
%90 = load i32, i32* %21
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %84
%93 = load i32, i32* @ENOMEM
%94 = sub nsw i32 0, %93
store i32 %94, i32* %21
br label %194
95: ; preds = %84
%96 = load i8*, i8** %26
%97 = call i32* @fopen(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %97, i32** %20
%98 = load i32*, i32** %20
%99 = icmp ne i32* %98, null
br i1 %99, label %106, label %100
100: ; preds = %95
%101 = load i32, i32* @errno
%102 = sub nsw i32 0, %101
store i32 %102, i32* %21
%103 = load i32, i32* @stderr
%104 = load i8*, i8** %26
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %104)
br label %187
106: ; preds = %95
%107 = load i32*, i32** %20
%108 = load i32*, i32** %13
%109 = load i32*, i32** %14
%110 = call i32 @fscanf(i32* %107, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %28, i8* %27, i32* %108, i32* %29, i32* %109)
store i32 %110, i32* %21
%111 = load i32, i32* %21
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %118
113: ; preds = %106
%114 = load i32, i32* @errno
%115 = sub nsw i32 0, %114
store i32 %115, i32* %21
%116 = load i32, i32* @stderr
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %176
118: ; preds = %106
%119 = load i32, i32* %21
%120 = icmp ne i32 %119, 5
br i1 %120, label %121, label %126
121: ; preds = %118
%122 = load i32, i32* @EIO
%123 = sub nsw i32 0, %122
store i32 %123, i32* %21
%124 = load i32, i32* @stderr
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %176
126: ; preds = %118
br label %127
127: ; preds = %126
%128 = load i8, i8* %28
%129 = sext i8 %128 to i32
%130 = icmp eq i32 %129, 98
%131 = zext i1 %130 to i32
%132 = load i32*, i32** %16
store i32 %131, i32* %132
%133 = load i32, i32* %29
%134 = udiv i32 %133, 8
%135 = load i32*, i32** %12
store i32 %134, i32* %135
%136 = load i32*, i32** %13
%137 = load i32, i32* %136
%138 = icmp eq i32 %137, 64
br i1 %138, label %139, label %141
139: ; preds = %127
%140 = load i64*, i64** %15
store i64 -1, i64* %140
br label %148
141: ; preds = %127
%142 = load i32*, i32** %13
%143 = load i32, i32* %142
%144 = zext i32 %143 to i64
%145 = shl i64 1, %144
%146 = sub i64 %145, 1
%147 = load i64*, i64** %15
store i64 %146, i64* %147
br label %148
148: ; preds = %141, %139
%149 = load i8, i8* %27
%150 = sext i8 %149 to i32
%151 = icmp eq i32 %150, 115
%152 = zext i1 %151 to i32
%153 = load i32*, i32** %11
store i32 %152, i32* %153
%154 = load i32*, i32** %20
%155 = call i64 @fclose(i32* %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %163
157: ; preds = %148
%158 = load i32, i32* @errno
%159 = sub nsw i32 0, %158
store i32 %159, i32* %21
%160 = load i32, i32* @stderr
%161 = load i8*, i8** %26
%162 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %161)
br label %187
163: ; preds = %148
store i32* null, i32** %20
%164 = load i8*, i8** %26
%165 = call i32 @free(i8* %164)
store i8* null, i8** %26
%166 = load i8*, i8** %24
%167 = load %struct.dirent*, %struct.dirent** %30
%168 = getelementptr inbounds %struct.dirent, %struct.dirent* %167, i32 0, i32 0
%169 = load i32, i32* %168
%170 = call i64 @strcmp(i8* %166, i32 %169)
%171 = icmp eq i64 %170, 0
br i1 %171, label %172, label %173
172: ; preds = %163
br label %175
173: ; preds = %163
br label %174
174: ; preds = %173, %77
br label %65
175: ; preds = %172, %65
br label %176
176: ; preds = %175, %121, %113
%177 = load i32*, i32** %20
%178 = icmp ne i32* %177, null
br i1 %178, label %179, label %186
179: ; preds = %176
%180 = load i32*, i32** %20
%181 = call i64 @fclose(i32* %180)
%182 = icmp ne i64 %181, 0
br i1 %182, label %183, label %185
183: ; preds = %179
%184 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %185
185: ; preds = %183, %179
br label %186
186: ; preds = %185, %176
br label %187
187: ; preds = %186, %157, %100
%188 = load i8*, i8** %26
%189 = icmp ne i8* %188, null
br i1 %189, label %190, label %193
190: ; preds = %187
%191 = load i8*, i8** %26
%192 = call i32 @free(i8* %191)
br label %193
193: ; preds = %190, %187
br label %194
194: ; preds = %193, %92
%195 = load i32*, i32** %22
%196 = call i32 @closedir(i32* %195)
%197 = icmp eq i32 %196, -1
br i1 %197, label %198, label %200
198: ; preds = %194
%199 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
br label %200
200: ; preds = %198, %194
br label %201
201: ; preds = %200, %59
%202 = load i8*, i8** %25
%203 = call i32 @free(i8* %202)
br label %204
204: ; preds = %201, %51
%205 = load i8*, i8** %24
%206 = call i32 @free(i8* %205)
br label %207
207: ; preds = %204, %43
%208 = load i8*, i8** %23
%209 = call i32 @free(i8* %208)
%210 = load i32, i32* %21
store i32 %210, i32* %10
br label %211
211: ; preds = %207, %35
%212 = load i32, i32* %10
ret i32 %212
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [17 x i8] c"%s/scan_elements\00"
@ENOMEM = global i32 0
@.str.1 = [8 x i8] c"%s_type\00"
@errno = global i32 0
@ENOENT = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [19 x i8] c"failed to open %s\0A\00"
@.str.5 = [16 x i8] c"%ce:%c%u/%u>>%u\00"
@.str.6 = [38 x i8] c"failed to pass scan type description\0A\00"
@EIO = global i32 0
@.str.7 = [36 x i8] c"scan type description didn't match\0A\00"
@.str.8 = [20 x i8] c"Failed to close %s\0A\00"
@.str.9 = [42 x i8] c"iioutils_get_type(): Failed to close file\00"
@.str.10 = [47 x i8] c"iioutils_get_type(): Failed to close directory\00"
define i32 @iioutils_get_type(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32* %2, i32* %3, i64* nocapture writeonly %4, i32* nocapture writeonly %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8
%15 = alloca i8
%16 = alloca i32
%17 = bitcast i8** %10 to i8*
%18 = bitcast i8** %11 to i8*
%19 = bitcast i8** %12 to i8*
%20 = bitcast i8** %13 to i8*
store i8* null, i8** %13
%21 = bitcast i32* %16 to i8*
%22 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %6)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %9
%25 = load i32, i32* @ENOMEM
%26 = sub nsw i32 0, %25
br label %156
27: ; preds = %9
%28 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @ENOMEM
%32 = sub nsw i32 0, %31
br label %152
33: ; preds = %27
%34 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @ENOMEM
%38 = sub nsw i32 0, %37
br label %148
39: ; preds = %33
%40 = load i8*, i8** %10
%41 = call i32* @opendir(i8* %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @errno
%45 = sub nsw i32 0, %44
br label %144
46: ; preds = %39
%47 = load i32, i32* @ENOENT
%48 = sub nsw i32 0, %47
%49 = call %struct.dirent* @readdir(i32* %41)
%50 = icmp eq %struct.dirent* %49, null
br i1 %50, label %132, label %51
51: ; preds = %46, %117
%52 = phi %struct.dirent* [ %119, %117 ], [ %49, %46 ]
%53 = phi i32 [ %118, %117 ], [ %48, %46 ]
%54 = load i8*, i8** %11
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i64 @strcmp(i8* %54, i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %51
%60 = load i8*, i8** %12
%61 = load i32, i32* %55
%62 = call i64 @strcmp(i8* %60, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %117
64: ; preds = %59, %51
%65 = load i8*, i8** %10
%66 = load i32, i32* %55
%67 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %65, i32 %66)
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load i32, i32* @ENOMEM
%71 = sub nsw i32 0, %70
br label %138
72: ; preds = %64
%73 = load i8*, i8** %13
%74 = call i32* @fopen(i8* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i32, i32* @errno
%78 = sub nsw i32 0, %77
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %13
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %80)
br label %132
82: ; preds = %72
%83 = call i32 @fscanf(i32* %74, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %15, i8* %14, i32* %2, i32* %16, i32* %3)
%84 = icmp slt i32 %83, 0
br i1 %84, label %121, label %85
85: ; preds = %82
%86 = icmp eq i32 %83, 5
br i1 %86, label %87, label %121
87: ; preds = %85
%88 = load i8, i8* %15
%89 = icmp eq i8 %88, 98
%90 = zext i1 %89 to i32
store i32 %90, i32* %5
%91 = load i32, i32* %16
%92 = lshr i32 %91, 3
store i32 %92, i32* %1
%93 = load i32, i32* %2
%94 = icmp eq i32 %93, 64
%95 = zext i32 %93 to i64
%96 = shl nsw i64 -1, %95
%97 = xor i64 %96, -1
%98 = select i1 %94, i64 -1, i64 %97
store i64 %98, i64* %4
%99 = load i8, i8* %14
%100 = icmp eq i8 %99, 115
%101 = zext i1 %100 to i32
store i32 %101, i32* %0
%102 = call i64 @fclose(i32* %74)
%103 = icmp eq i64 %102, 0
br i1 %103, label %110, label %104
104: ; preds = %87
%105 = load i32, i32* @errno
%106 = sub nsw i32 0, %105
%107 = load i32, i32* @stderr
%108 = load i8*, i8** %13
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %108)
br label %132
110: ; preds = %87
%111 = load i8*, i8** %13
%112 = call i32 @free(i8* %111)
store i8* null, i8** %13
%113 = load i8*, i8** %11
%114 = load i32, i32* %55
%115 = call i64 @strcmp(i8* %113, i32 %114)
%116 = icmp eq i64 %115, 0
br i1 %116, label %132, label %117
117: ; preds = %110, %59
%118 = phi i32 [ 5, %110 ], [ %53, %59 ]
%119 = call %struct.dirent* @readdir(i32* %41)
%120 = icmp eq %struct.dirent* %119, null
br i1 %120, label %132, label %51
121: ; preds = %85, %82
%122 = phi i32* [ @errno, %82 ], [ @EIO, %85 ]
%123 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), %82 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), %85 ]
%124 = load i32, i32* %122
%125 = load i32, i32* @stderr
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* %123)
%127 = sub nsw i32 0, %124
%128 = call i64 @fclose(i32* %74)
%129 = icmp eq i64 %128, 0
br i1 %129, label %132, label %130
130: ; preds = %121
%131 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %132
132: ; preds = %110, %117, %46, %130, %121, %104, %76
%133 = phi i32 [ %127, %130 ], [ %127, %121 ], [ %106, %104 ], [ %78, %76 ], [ %48, %46 ], [ 5, %110 ], [ %118, %117 ]
%134 = load i8*, i8** %13
%135 = icmp eq i8* %134, null
br i1 %135, label %138, label %136
136: ; preds = %132
%137 = call i32 @free(i8* %134)
br label %138
138: ; preds = %132, %136, %69
%139 = phi i32 [ %71, %69 ], [ %133, %136 ], [ %133, %132 ]
%140 = call i32 @closedir(i32* %41)
%141 = icmp eq i32 %140, -1
br i1 %141, label %142, label %144
142: ; preds = %138
%143 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
br label %144
144: ; preds = %138, %142, %43
%145 = phi i32 [ %139, %142 ], [ %139, %138 ], [ %45, %43 ]
%146 = load i8*, i8** %12
%147 = call i32 @free(i8* %146)
br label %148
148: ; preds = %144, %36
%149 = phi i32 [ %38, %36 ], [ %145, %144 ]
%150 = load i8*, i8** %11
%151 = call i32 @free(i8* %150)
br label %152
152: ; preds = %148, %30
%153 = phi i32 [ %32, %30 ], [ %149, %148 ]
%154 = load i8*, i8** %10
%155 = call i32 @free(i8* %154)
br label %156
156: ; preds = %152, %24
%157 = phi i32 [ %26, %24 ], [ %153, %152 ]
ret i32 %157
}