#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;
    }
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    1593 <iioutils_get_type+0x3e3>
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    1584 <iioutils_get_type+0x3d4>
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    157b <iioutils_get_type+0x3cb>
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    1572 <iioutils_get_type+0x3c2>
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     14fd <iioutils_get_type+0x34d>
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    14f8 <iioutils_get_type+0x348>
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    154f <iioutils_get_type+0x39f>
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    1536 <iioutils_get_type+0x386>
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    1502 <iioutils_get_type+0x352>
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    1502 <iioutils_get_type+0x352>
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    1536 <iioutils_get_type+0x386>
movq   $0x0,-0x40(%rbp)
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x70(%rbp)
jmp    12c2 <iioutils_get_type+0x112>
jmp    1502 <iioutils_get_type+0x352>
cmpq   $0x0,-0x40(%rbp)
je     1531 <iioutils_get_type+0x381>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     152c <iioutils_get_type+0x37c>
lea    0xb7b(%rip),%rdi
call   10d0 <perror@plt>
jmp    1531 <iioutils_get_type+0x381>
jmp    1536 <iioutils_get_type+0x386>
cmpq   $0x0,-0x70(%rbp)
je     154a <iioutils_get_type+0x39a>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
jmp    154f <iioutils_get_type+0x39f>
mov    -0x50(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
jne    156d <iioutils_get_type+0x3bd>
lea    0xb64(%rip),%rdi
call   10d0 <perror@plt>
jmp    1572 <iioutils_get_type+0x3c2>
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    $0x68,%rsp
mov    %r9,%r15
mov    %r8,%rbx
mov    %rcx,0x60(%rsp)
mov    %rdx,0x58(%rsp)
mov    %rsi,%r13
mov    %rdi,%r14
mov    0xa0(%rsp),%rdx
movq   $0x0,0x18(%rsp)
lea    0xe14(%rip),%rsi
xor    %ebp,%ebp
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13d1 <iioutils_get_type+0x221>
mov    0xa8(%rsp),%rdx
lea    0xe00(%rip),%rsi
xor    %ebp,%ebp
lea    0x38(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13df <iioutils_get_type+0x22f>
mov    0xb0(%rsp),%rdx
lea    0xddb(%rip),%rsi
xor    %ebp,%ebp
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     13ed <iioutils_get_type+0x23d>
mov    %rbx,0x50(%rsp)
mov    0x20(%rsp),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     13fb <iioutils_get_type+0x24b>
mov    %rax,%r12
mov    %r15,0x48(%rsp)
mov    0x2d45(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %r12,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     14b4 <iioutils_get_type+0x304>
mov    %rax,%rbx
mov    %r13,0x40(%rsp)
mov    0x60(%rsp),%r13
mov    0x58(%rsp),%r15
jmp    12b4 <iioutils_get_type+0x104>
nopl   0x0(%rax)
mov    %r12,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     14b4 <iioutils_get_type+0x304>
mov    0x38(%rsp),%rdi
mov    (%rbx),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12d6 <iioutils_get_type+0x126>
mov    0x30(%rsp),%rdi
mov    (%rbx),%esi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12a0 <iioutils_get_type+0xf0>
mov    0x20(%rsp),%rdx
mov    (%rbx),%ecx
lea    0x18(%rsp),%rdi
lea    0xd30(%rip),%rsi
xor    %eax,%eax
call   10b0 <asprintf@plt>
test   %eax,%eax
js     140b <iioutils_get_type+0x25b>
mov    %r12,%rbx
mov    0x18(%rsp),%rdi
lea    0xd18(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     141b <iioutils_get_type+0x26b>
mov    %rax,%r12
mov    %r13,(%rsp)
mov    %rax,%rdi
lea    0xd0e(%rip),%rsi
lea    0x16(%rsp),%rdx
lea    0x17(%rsp),%rcx
mov    %r15,%r8
lea    0x2c(%rsp),%r9
call   1060 <fscanf@plt>
test   %eax,%eax
js     143d <iioutils_get_type+0x28d>
cmp    $0x5,%eax
jne    144d <iioutils_get_type+0x29d>
xor    %eax,%eax
cmpb   $0x62,0x16(%rsp)
sete   %al
mov    0x48(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x2c(%rsp),%eax
shr    $0x3,%eax
mov    0x40(%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    0x50(%rsp),%rcx
mov    %rax,(%rcx)
xor    %eax,%eax
cmpb   $0x73,0x17(%rsp)
sete   %al
mov    %eax,(%r14)
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    148a <iioutils_get_type+0x2da>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,0x18(%rsp)
mov    $0x5,%ebp
mov    %rbx,%r12
jmp    12a0 <iioutils_get_type+0xf0>
mov    0x2c00(%rip),%rax
sub    (%rax),%ebp
jmp    14ee <iioutils_get_type+0x33e>
mov    0x2bf2(%rip),%rax
sub    (%rax),%ebp
jmp    14e4 <iioutils_get_type+0x334>
mov    0x2be4(%rip),%rax
sub    (%rax),%ebp
jmp    14da <iioutils_get_type+0x32a>
mov    0x2bc6(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14d0 <iioutils_get_type+0x320>
mov    0x2bc6(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    14c3 <iioutils_get_type+0x313>
mov    0x2ba6(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rdx
lea    0xbe6(%rip),%rsi
jmp    14aa <iioutils_get_type+0x2fa>
lea    0xc00(%rip),%rsi
mov    0x2b7d(%rip),%rcx
jmp    145b <iioutils_get_type+0x2ab>
mov    0x2b8c(%rip),%rcx
lea    0xc0f(%rip),%rsi
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
sub    (%rcx),%ebp
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     14b1 <iioutils_get_type+0x301>
lea    0xc1f(%rip),%rdi
call   10d0 <perror@plt>
jmp    14b1 <iioutils_get_type+0x301>
mov    0x2b37(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rdx
lea    0xbe4(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%r12
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     14c3 <iioutils_get_type+0x313>
call   1030 <free@plt>
mov    %r12,%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
je     14ff <iioutils_get_type+0x34f>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
mov    0x38(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbc6(%rip),%rdi
call   10d0 <perror@plt>
jmp    14d0 <iioutils_get_type+0x320>

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 %203
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 %199
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 %196
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 %193
62: ; preds = %54
%63 = load i32, i32* @ENOENT
%64 = sub nsw i32 0, %63
store i32 %64, i32* %21
br label %65
65: ; preds = %166, %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 %167
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 %166
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 %186
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 %179
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 %168
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 %168
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 %179
163: ; preds = %148
store i32* null, i32** %20
%164 = load i8*, i8** %26
%165 = call i32 @free(i8* %164)
store i8* null, i8** %26
br label %166
166: ; preds = %163, %77
br label %65
167: ; preds = %65
br label %168
168: ; preds = %167, %121, %113
%169 = load i32*, i32** %20
%170 = icmp ne i32* %169, null
br i1 %170, label %171, label %178
171: ; preds = %168
%172 = load i32*, i32** %20
%173 = call i64 @fclose(i32* %172)
%174 = icmp ne i64 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %171
%176 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %177
177: ; preds = %175, %171
br label %178
178: ; preds = %177, %168
br label %179
179: ; preds = %178, %157, %100
%180 = load i8*, i8** %26
%181 = icmp ne i8* %180, null
br i1 %181, label %182, label %185
182: ; preds = %179
%183 = load i8*, i8** %26
%184 = call i32 @free(i8* %183)
br label %185
185: ; preds = %182, %179
br label %186
186: ; preds = %185, %92
%187 = load i32*, i32** %22
%188 = call i32 @closedir(i32* %187)
%189 = icmp eq i32 %188, -1
br i1 %189, label %190, label %192
190: ; preds = %186
%191 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
br label %192
192: ; preds = %190, %186
br label %193
193: ; preds = %192, %59
%194 = load i8*, i8** %25
%195 = call i32 @free(i8* %194)
br label %196
196: ; preds = %193, %51
%197 = load i8*, i8** %24
%198 = call i32 @free(i8* %197)
br label %199
199: ; preds = %196, %43
%200 = load i8*, i8** %23
%201 = call i32 @free(i8* %200)
%202 = load i32, i32* %21
store i32 %202, i32* %10
br label %203
203: ; preds = %199, %35
%204 = load i32, i32* %10
ret i32 %204
}

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 %152
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 %148
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 %144
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 %140
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 %128, label %51
51: ; preds = %46, %113
%52 = phi %struct.dirent* [ %115, %113 ], [ %49, %46 ]
%53 = phi i32 [ %114, %113 ], [ %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 %113
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 %134
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 %128
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 %117, label %85
85: ; preds = %82
%86 = icmp eq i32 %83, 5
br i1 %86, label %87, label %117
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 %128
110: ; preds = %87
%111 = load i8*, i8** %13
%112 = call i32 @free(i8* %111)
store i8* null, i8** %13
br label %113
113: ; preds = %110, %59
%114 = phi i32 [ 5, %110 ], [ %53, %59 ]
%115 = call %struct.dirent* @readdir(i32* %41)
%116 = icmp eq %struct.dirent* %115, null
br i1 %116, label %128, label %51
117: ; preds = %85, %82
%118 = phi i32* [ @errno, %82 ], [ @EIO, %85 ]
%119 = 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 ]
%120 = load i32, i32* %118
%121 = load i32, i32* @stderr
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* %119)
%123 = sub nsw i32 0, %120
%124 = call i64 @fclose(i32* %74)
%125 = icmp eq i64 %124, 0
br i1 %125, label %128, label %126
126: ; preds = %117
%127 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %128
128: ; preds = %113, %46, %126, %117, %104, %76
%129 = phi i32 [ %123, %126 ], [ %123, %117 ], [ %106, %104 ], [ %78, %76 ], [ %48, %46 ], [ %114, %113 ]
%130 = load i8*, i8** %13
%131 = icmp eq i8* %130, null
br i1 %131, label %134, label %132
132: ; preds = %128
%133 = call i32 @free(i8* %130)
br label %134
134: ; preds = %128, %132, %69
%135 = phi i32 [ %71, %69 ], [ %129, %132 ], [ %129, %128 ]
%136 = call i32 @closedir(i32* %41)
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %140
138: ; preds = %134
%139 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
br label %140
140: ; preds = %134, %138, %43
%141 = phi i32 [ %135, %138 ], [ %135, %134 ], [ %45, %43 ]
%142 = load i8*, i8** %12
%143 = call i32 @free(i8* %142)
br label %144
144: ; preds = %140, %36
%145 = phi i32 [ %38, %36 ], [ %141, %140 ]
%146 = load i8*, i8** %11
%147 = call i32 @free(i8* %146)
br label %148
148: ; preds = %144, %30
%149 = phi i32 [ %32, %30 ], [ %145, %144 ]
%150 = load i8*, i8** %10
%151 = call i32 @free(i8* %150)
br label %152
152: ; preds = %148, %24
%153 = phi i32 [ %26, %24 ], [ %149, %148 ]
ret i32 %153
}