#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 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);
int iioutils_get_type(unsigned int *is_signed, unsigned int *bytes,
                      unsigned int *bits_used, unsigned int *shift,
                      uint64_t *mask, unsigned int *be, const char *device_dir,
                      int buffer_idx, 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/buffer%d", device_dir, buffer_idx);
  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 = ~(0ULL);
      else
        *mask = (1ULL << *bits_used) - 1ULL;
      *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    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
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
mov    0x18(%rbp),%ecx
lea    -0x58(%rbp),%rdi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1223 <iioutils_get_type+0x73>
xor    %eax,%eax
mov    0x2dbf(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    15bc <iioutils_get_type+0x40c>
mov    0x20(%rbp),%rdx
lea    -0x60(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1259 <iioutils_get_type+0xa9>
xor    %eax,%eax
mov    0x2d89(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    15ad <iioutils_get_type+0x3fd>
mov    0x28(%rbp),%rdx
lea    -0x68(%rbp),%rdi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    128f <iioutils_get_type+0xdf>
xor    %eax,%eax
mov    0x2d53(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    15a4 <iioutils_get_type+0x3f4>
mov    -0x58(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12ba <iioutils_get_type+0x10a>
xor    %eax,%eax
mov    0x2d18(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    159b <iioutils_get_type+0x3eb>
xor    %eax,%eax
mov    0x2cf5(%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     1526 <iioutils_get_type+0x376>
mov    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1312 <iioutils_get_type+0x162>
mov    -0x68(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1521 <iioutils_get_type+0x371>
mov    -0x58(%rbp),%rdx
mov    -0x80(%rbp),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%rdi
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   10b0 <asprintf@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    134e <iioutils_get_type+0x19e>
xor    %eax,%eax
mov    0x2c94(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    1578 <iioutils_get_type+0x3c8>
mov    -0x70(%rbp),%rdi
lea    0xcc1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    139b <iioutils_get_type+0x1eb>
xor    %eax,%eax
mov    0x2c52(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rdx
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    155f <iioutils_get_type+0x3af>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%rax
lea    0xc81(%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    13fa <iioutils_get_type+0x24a>
xor    %eax,%eax
mov    0x2bef(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
lea    0xc51(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    152b <iioutils_get_type+0x37b>
cmpl   $0x5,-0x44(%rbp)
je     142e <iioutils_get_type+0x27e>
xor    %eax,%eax
mov    0x2bd3(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
lea    0xc43(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    152b <iioutils_get_type+0x37b>
jmp    1433 <iioutils_get_type+0x283>
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    1471 <iioutils_get_type+0x2c1>
mov    -0x30(%rbp),%rax
movq   $0xffffffffffffffff,(%rax)
jmp    148f <iioutils_get_type+0x2df>
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     14e5 <iioutils_get_type+0x335>
xor    %eax,%eax
mov    0x2b08(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rdx
lea    0xbb0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    155f <iioutils_get_type+0x3af>
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    151c <iioutils_get_type+0x36c>
jmp    1526 <iioutils_get_type+0x376>
jmp    1521 <iioutils_get_type+0x371>
jmp    12c8 <iioutils_get_type+0x118>
jmp    152b <iioutils_get_type+0x37b>
cmpq   $0x0,-0x40(%rbp)
je     155a <iioutils_get_type+0x3aa>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1555 <iioutils_get_type+0x3a5>
lea    0xb4d(%rip),%rdi
call   10d0 <perror@plt>
jmp    155a <iioutils_get_type+0x3aa>
jmp    155f <iioutils_get_type+0x3af>
cmpq   $0x0,-0x70(%rbp)
je     1573 <iioutils_get_type+0x3c3>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
jmp    1578 <iioutils_get_type+0x3c8>
mov    -0x50(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
jne    1596 <iioutils_get_type+0x3e6>
lea    0xb36(%rip),%rdi
call   10d0 <perror@plt>
jmp    159b <iioutils_get_type+0x3eb>
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
mov    0x98(%rsp),%ecx
movq   $0x0,0x10(%rsp)
lea    0xe0f(%rip),%rsi
xor    %ebp,%ebp
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13ec <iioutils_get_type+0x23c>
mov    0xa0(%rsp),%rdx
lea    0xdf6(%rip),%rsi
xor    %ebp,%ebp
lea    0x18(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13fa <iioutils_get_type+0x24a>
mov    0xa8(%rsp),%rdx
lea    0xdd1(%rip),%rsi
xor    %ebp,%ebp
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     1408 <iioutils_get_type+0x258>
mov    %rbx,0x48(%rsp)
mov    0x20(%rsp),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1416 <iioutils_get_type+0x266>
mov    %rax,%rbx
mov    %r12,0x38(%rsp)
mov    %r14,0x40(%rsp)
mov    0x2d3b(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     14cc <iioutils_get_type+0x31c>
mov    %rax,%r12
jmp    12b4 <iioutils_get_type+0x104>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     14cc <iioutils_get_type+0x31c>
mov    0x18(%rsp),%rdi
mov    (%r12),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12da <iioutils_get_type+0x12a>
mov    0x30(%rsp),%rdi
mov    (%r12),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12a0 <iioutils_get_type+0xf0>
mov    0x20(%rsp),%rdx
mov    (%r12),%ecx
lea    0x10(%rsp),%rdi
lea    0xd25(%rip),%rsi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     1426 <iioutils_get_type+0x276>
mov    0x10(%rsp),%rdi
lea    0xd10(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1436 <iioutils_get_type+0x286>
mov    %rax,%r14
mov    %r13,(%rsp)
mov    %rax,%rdi
lea    0xd06(%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     1458 <iioutils_get_type+0x2a8>
cmp    $0x5,%eax
jne    1468 <iioutils_get_type+0x2b8>
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    14a5 <iioutils_get_type+0x2f5>
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    12a0 <iioutils_get_type+0xf0>
jmp    14cc <iioutils_get_type+0x31c>
mov    0x2be5(%rip),%rax
sub    (%rax),%ebp
jmp    1506 <iioutils_get_type+0x356>
mov    0x2bd7(%rip),%rax
sub    (%rax),%ebp
jmp    14fc <iioutils_get_type+0x34c>
mov    0x2bc9(%rip),%rax
sub    (%rax),%ebp
jmp    14f2 <iioutils_get_type+0x342>
mov    0x2bab(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14e8 <iioutils_get_type+0x338>
mov    0x2bab(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14db <iioutils_get_type+0x32b>
mov    0x2b8b(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xbc6(%rip),%rsi
jmp    14c5 <iioutils_get_type+0x315>
lea    0xbe0(%rip),%rsi
mov    0x2b62(%rip),%rcx
jmp    1476 <iioutils_get_type+0x2c6>
mov    0x2b71(%rip),%rcx
lea    0xbef(%rip),%rsi
mov    0x2b53(%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     14cc <iioutils_get_type+0x31c>
lea    0xbff(%rip),%rdi
call   10d0 <perror@plt>
jmp    14cc <iioutils_get_type+0x31c>
mov    0x2b1c(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xbc4(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     14db <iioutils_get_type+0x32b>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
je     1517 <iioutils_get_type+0x367>
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    0xba9(%rip),%rdi
call   10d0 <perror@plt>
jmp    14e8 <iioutils_get_type+0x338>

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

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