#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct gpioline_info {
  char *name;
  char *label;
  int lines;
  int line_offset;
  char *consumer;
  scalar_t__ flags;
};
struct gpiochip_info {
  char *name;
  char *label;
  int lines;
  int line_offset;
  char *consumer;
  scalar_t__ flags;
};
typedef int /*<<< orphan*/ linfo;

/* Variables and functions */
int ENOMEM;
int /*<<< orphan*/ GPIO_GET_CHIPINFO_IOCTL;
int /*<<< orphan*/ GPIO_GET_LINEINFO_IOCTL;
int asprintf(char **, char *, char const *);
int close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int ioctl(int, int /*<<< orphan*/, struct gpioline_info *);
int /*<<< orphan*/ memset(struct gpioline_info *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_flags(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int list_device(const char *device_name) {
  struct gpiochip_info cinfo;
  char *chrdev_name;
  int fd;
  int ret;
  int i;
  ret = asprintf(&chrdev_name, "/dev/%s", device_name);
  if (ret < 0) {
    return -ENOMEM;
  }
  fd = open(chrdev_name, 0);
  if (fd == -1) {
    ret = -errno;
    fprintf(stderr, "Failed to open %s\n", chrdev_name);
    goto exit_close_error;
  }
  ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &cinfo);
  if (ret == -1) {
    ret = -errno;
    perror("Failed to issue CHIPINFO IOCTL\n");
    goto exit_close_error;
  }
  fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n", cinfo.name,
          cinfo.label, cinfo.lines);
  for (i = 0; i < cinfo.lines; i++) {
    struct gpioline_info linfo;
    memset(&linfo, 0, sizeof(linfo));
    linfo.line_offset = i;
    ret = ioctl(fd, GPIO_GET_LINEINFO_IOCTL, &linfo);
    if (ret == -1) {
      ret = -errno;
      perror("Failed to issue LINEINFO IOCTL\n");
      goto exit_close_error;
    }
    fprintf(stdout, "\tline %2d:", linfo.line_offset);
    if (linfo.name[0]) {
      fprintf(stdout, " \"%s\"", linfo.name);
    } else {
      fprintf(stdout, " unnamed");
    }
    if (linfo.consumer[0]) {
      fprintf(stdout, " \"%s\"", linfo.consumer);
    } else {
      fprintf(stdout, " unused");
    }
    if (linfo.flags) {
      fprintf(stdout, " [");
      print_flags(linfo.flags);
      fprintf(stdout, "]");
    }
    fprintf(stdout, "\n");
  }
exit_close_error:
  if (close(fd) == -1) {
    perror("Failed to close GPIO character device file");
  }
  free(chrdev_name);
  return ret;
}


x86 assembly (clang, -O0):
<list_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1090 <asprintf@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    11d3 <list_device+0x43>
xor    %eax,%eax
mov    0x2e07(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1421 <list_device+0x291>
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
call   10a0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1219 <list_device+0x89>
xor    %eax,%eax
mov    0x2dcc(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x48(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13f5 <list_device+0x265>
mov    -0x44(%rbp),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    125a <list_device+0xca>
xor    %eax,%eax
mov    0x2d7c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x48(%rbp)
lea    0xdcb(%rip),%rdi
call   10b0 <perror@plt>
jmp    13f5 <list_device+0x265>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8d
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13f0 <list_device+0x260>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    -0x78(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    12e7 <list_device+0x157>
xor    %eax,%eax
mov    0x2cef(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x48(%rbp)
lea    0xd82(%rip),%rdi
call   10b0 <perror@plt>
jmp    13f5 <list_device+0x265>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    -0x64(%rbp),%edx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%rax
cmpb   $0x0,(%rax)
je     132e <list_device+0x19e>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    -0x78(%rbp),%rdx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1345 <list_device+0x1b5>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x60(%rbp),%rax
cmpb   $0x0,(%rax)
je     1372 <list_device+0x1e2>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1389 <list_device+0x1f9>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x58(%rbp)
je     13cb <list_device+0x23b>
mov    0x2c1d(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1080 <print_flags@plt>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xca2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1284 <list_device+0xf4>
jmp    13f5 <list_device+0x265>
mov    -0x44(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1412 <list_device+0x282>
lea    0xc99(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_device>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rdx
lea    0xe58(%rip),%rsi
mov    %rsp,%rdi
call   1090 <asprintf@plt>
test   %eax,%eax
js     135b <list_device+0x1cb>
mov    (%rsp),%rdi
xor    %esi,%esi
call   10a0 <open@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     1368 <list_device+0x1d8>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rdx
mov    %r14d,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     13c3 <list_device+0x233>
mov    %eax,%ebp
mov    0x2dc1(%rip),%r15
mov    (%r15),%edi
mov    0x30(%rsp),%rdx
mov    0x38(%rsp),%rcx
mov    0x40(%rsp),%r8d
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpl   $0x0,0x40(%rsp)
jle    138e <list_device+0x1fe>
lea    0x8(%rsp),%rbx
lea    0xe5c(%rip),%r13
xor    %r12d,%r12d
jmp    1260 <list_device+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r12d
cmp    0x40(%rsp),%r12d
jge    138e <list_device+0x1fe>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    %r12d,0x1c(%rsp)
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     13dc <list_device+0x24c>
mov    %eax,%ebp
mov    (%r15),%edi
mov    0x1c(%rsp),%edx
lea    0xdde(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdx
cmpb   $0x0,(%rdx)
mov    (%r15),%edi
je     12d0 <list_device+0x140>
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12de <list_device+0x14e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x20(%rsp),%rdx
cmpb   $0x0,(%rdx)
mov    (%r15),%edi
je     1310 <list_device+0x180>
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpq   $0x0,0x28(%rsp)
jne    132a <list_device+0x19a>
jmp    1240 <list_device+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd82(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
cmpq   $0x0,0x28(%rsp)
je     1240 <list_device+0xb0>
mov    (%r15),%edi
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x28(%rsp),%rdi
call   1080 <print_flags@plt>
mov    (%r15),%edi
lea    0xd55(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1240 <list_device+0xb0>
mov    0x2c6e(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    13a4 <list_device+0x214>
mov    0x2c51(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rdx
lea    0xc81(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
je     13b5 <list_device+0x225>
mov    (%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    0xcea(%rip),%rdi
call   10b0 <perror@plt>
jmp    139b <list_device+0x20b>
mov    0x2bf6(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
lea    0xc46(%rip),%rdi
call   10b0 <perror@plt>
jmp    138e <list_device+0x1fe>
mov    0x2bdd(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
lea    0xc71(%rip),%rdi
call   10b0 <perror@plt>
jmp    138e <list_device+0x1fe>

LLVM IR (-O0):
%struct.gpiochip_info = type { i8*, i8*, i32, i32, i8*, i64 }
%struct.gpioline_info = type { i8*, i8*, i32, i32, i8*, i64 }
@.str = [8 x i8] c"/dev/%s\00"
@ENOMEM = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Failed to open %s\0A\00"
@GPIO_GET_CHIPINFO_IOCTL = global i32 0
@.str.2 = [32 x i8] c"Failed to issue CHIPINFO IOCTL\0A\00"
@stdout = global i32 0
@.str.3 = [36 x i8] c"GPIO chip: %s, \22%s\22, %u GPIO lines\0A\00"
@GPIO_GET_LINEINFO_IOCTL = global i32 0
@.str.4 = [32 x i8] c"Failed to issue LINEINFO IOCTL\0A\00"
@.str.5 = [11 x i8] c"\09line %2d:\00"
@.str.6 = [6 x i8] c" \22%s\22\00"
@.str.7 = [9 x i8] c" unnamed\00"
@.str.8 = [8 x i8] c" unused\00"
@.str.9 = [3 x i8] c" [\00"
@.str.10 = [2 x i8] c"]\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [43 x i8] c"Failed to close GPIO character device file\00"
define i32 @list_device(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.gpiochip_info
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.gpioline_info
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* @ENOMEM
%16 = sub nsw i32 0, %15
store i32 %16, i32* %2
br label %127
17: ; preds = %1
%18 = load i8*, i8** %5
%19 = call i32 @open(i8* %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = sub nsw i32 0, %23
store i32 %24, i32* %7
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %5
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %117
28: ; preds = %17
%29 = load i32, i32* %6
%30 = load i32, i32* @GPIO_GET_CHIPINFO_IOCTL
%31 = bitcast %struct.gpiochip_info* %4 to %struct.gpioline_info*
%32 = call i32 @ioctl(i32 %29, i32 %30, %struct.gpioline_info* %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* @errno
%37 = sub nsw i32 0, %36
store i32 %37, i32* %7
%38 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %117
39: ; preds = %28
%40 = load i32, i32* @stdout
%41 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %4, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %4, i32 0, i32 1
%44 = load i8*, i8** %43
%45 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %4, i32 0, i32 2
%46 = load i32, i32* %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %44, i32 %46)
store i32 0, i32* %8
br label %48
48: ; preds = %113, %39
%49 = load i32, i32* %8
%50 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %4, i32 0, i32 2
%51 = load i32, i32* %50
%52 = icmp slt i32 %49, %51
br i1 %52, label %53, label %116
53: ; preds = %48
%54 = call i32 @memset(%struct.gpioline_info* %9, i32 0, i32 40)
%55 = load i32, i32* %8
%56 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 3
store i32 %55, i32* %56
%57 = load i32, i32* %6
%58 = load i32, i32* @GPIO_GET_LINEINFO_IOCTL
%59 = call i32 @ioctl(i32 %57, i32 %58, %struct.gpioline_info* %9)
store i32 %59, i32* %7
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %53
%63 = load i32, i32* @errno
%64 = sub nsw i32 0, %63
store i32 %64, i32* %7
%65 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %117
66: ; preds = %53
%67 = load i32, i32* @stdout
%68 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 3
%69 = load i32, i32* %68
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 0
%72 = load i8*, i8** %71
%73 = getelementptr inbounds i8, i8* %72, i64 0
%74 = load i8, i8* %73
%75 = icmp ne i8 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %66
%77 = load i32, i32* @stdout
%78 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 0
%79 = load i8*, i8** %78
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %79)
br label %84
81: ; preds = %66
%82 = load i32, i32* @stdout
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %84
84: ; preds = %81, %76
%85 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 4
%86 = load i8*, i8** %85
%87 = getelementptr inbounds i8, i8* %86, i64 0
%88 = load i8, i8* %87
%89 = icmp ne i8 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %84
%91 = load i32, i32* @stdout
%92 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 4
%93 = load i8*, i8** %92
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %93)
br label %98
95: ; preds = %84
%96 = load i32, i32* @stdout
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %98
98: ; preds = %95, %90
%99 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 5
%100 = load i64, i64* %99
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %98
%103 = load i32, i32* @stdout
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%105 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %9, i32 0, i32 5
%106 = load i64, i64* %105
%107 = call i32 @print_flags(i64 %106)
%108 = load i32, i32* @stdout
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %110
110: ; preds = %102, %98
%111 = load i32, i32* @stdout
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %113
113: ; preds = %110
%114 = load i32, i32* %8
%115 = add nsw i32 %114, 1
store i32 %115, i32* %8
br label %48
116: ; preds = %48
br label %117
117: ; preds = %116, %62, %35, %22
%118 = load i32, i32* %6
%119 = call i32 @close(i32 %118)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
br label %123
123: ; preds = %121, %117
%124 = load i8*, i8** %5
%125 = call i32 @free(i8* %124)
%126 = load i32, i32* %7
store i32 %126, i32* %2
br label %127
127: ; preds = %123, %14
%128 = load i32, i32* %2
ret i32 %128
}

LLVM IR (-O2):
%struct.gpiochip_info = type { i8*, i8*, i32, i32, i8*, i64 }
%struct.gpioline_info = type { i8*, i8*, i32, i32, i8*, i64 }
@.str = [8 x i8] c"/dev/%s\00"
@ENOMEM = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Failed to open %s\0A\00"
@GPIO_GET_CHIPINFO_IOCTL = global i32 0
@.str.2 = [32 x i8] c"Failed to issue CHIPINFO IOCTL\0A\00"
@stdout = global i32 0
@.str.3 = [36 x i8] c"GPIO chip: %s, \22%s\22, %u GPIO lines\0A\00"
@GPIO_GET_LINEINFO_IOCTL = global i32 0
@.str.4 = [32 x i8] c"Failed to issue LINEINFO IOCTL\0A\00"
@.str.5 = [11 x i8] c"\09line %2d:\00"
@.str.6 = [6 x i8] c" \22%s\22\00"
@.str.7 = [9 x i8] c" unnamed\00"
@.str.8 = [8 x i8] c" unused\00"
@.str.9 = [3 x i8] c" [\00"
@.str.10 = [2 x i8] c"]\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [43 x i8] c"Failed to close GPIO character device file\00"
define i32 @list_device(i8* %0) {
%2 = alloca %struct.gpiochip_info
%3 = alloca i8*
%4 = alloca %struct.gpioline_info
%5 = bitcast %struct.gpiochip_info* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @ENOMEM
%11 = sub nsw i32 0, %10
br label %104
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @open(i8* %13, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %95
22: ; preds = %12
%23 = load i32, i32* @GPIO_GET_CHIPINFO_IOCTL
%24 = bitcast %struct.gpiochip_info* %2 to %struct.gpioline_info*
%25 = call i32 @ioctl(i32 %14, i32 %23, %struct.gpioline_info* %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @errno
%29 = sub nsw i32 0, %28
%30 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %95
31: ; preds = %22
%32 = load i32, i32* @stdout
%33 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %2, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %2, i64 0, i32 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds %struct.gpiochip_info, %struct.gpiochip_info* %2, i64 0, i32 2
%38 = load i32, i32* %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %36, i32 %38)
%40 = load i32, i32* %37
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %95
42: ; preds = %31
%43 = bitcast %struct.gpioline_info* %4 to i8*
%44 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %4, i64 0, i32 3
%45 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %4, i64 0, i32 0
%46 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %4, i64 0, i32 4
%47 = getelementptr inbounds %struct.gpioline_info, %struct.gpioline_info* %4, i64 0, i32 5
br label %48
48: ; preds = %42, %89
%49 = phi i32 [ 0, %42 ], [ %92, %89 ]
%50 = call i32 @memset(%struct.gpioline_info* %4, i32 0, i32 40)
store i32 %49, i32* %44
%51 = load i32, i32* @GPIO_GET_LINEINFO_IOCTL
%52 = call i32 @ioctl(i32 %14, i32 %51, %struct.gpioline_info* %4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %85, label %54
54: ; preds = %48
%55 = load i32, i32* @stdout
%56 = load i32, i32* %44
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%58 = load i8*, i8** %45
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
%61 = load i32, i32* @stdout
br i1 %60, label %64, label %62
62: ; preds = %54
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %58)
br label %66
64: ; preds = %54
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %66
66: ; preds = %64, %62
%67 = load i8*, i8** %46
%68 = load i8, i8* %67
%69 = icmp eq i8 %68, 0
%70 = load i32, i32* @stdout
br i1 %69, label %73, label %71
71: ; preds = %66
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %67)
br label %75
73: ; preds = %66
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %75
75: ; preds = %73, %71
%76 = load i64, i64* %47
%77 = icmp eq i64 %76, 0
br i1 %77, label %89, label %78
78: ; preds = %75
%79 = load i32, i32* @stdout
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%81 = load i64, i64* %47
%82 = call i32 @print_flags(i64 %81)
%83 = load i32, i32* @stdout
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %89
85: ; preds = %48
%86 = load i32, i32* @errno
%87 = sub nsw i32 0, %86
%88 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %95
89: ; preds = %75, %78
%90 = load i32, i32* @stdout
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%92 = add nuw nsw i32 %49, 1
%93 = load i32, i32* %37
%94 = icmp slt i32 %92, %93
br i1 %94, label %48, label %95
95: ; preds = %89, %31, %85, %27, %16
%96 = phi i32 [ %18, %16 ], [ %29, %27 ], [ %87, %85 ], [ %25, %31 ], [ %52, %89 ]
%97 = call i32 @close(i32 %14)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
br label %101
101: ; preds = %99, %95
%102 = load i8*, i8** %3
%103 = call i32 @free(i8* %102)
br label %104
104: ; preds = %101, %9
%105 = phi i32 [ %11, %9 ], [ %96, %101 ]
ret i32 %105
}