#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 dvb_resource {
  int dummy;
};
struct dvb_frontend_info {
  char *name;
};

/* Variables and functions */
int /*<<< orphan*/ FE_GET_INFO;
int /*<<< orphan*/ O_RDWR;
int _dvbres_error(struct dvb_resource *, char *, int);
int _dvbres_ok(struct dvb_resource *);
int close(int);
int errno;
int ioctl(int, int /*<<< orphan*/, struct dvb_frontend_info *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int dvbres_listdevices(struct dvb_resource *res, char *buffer, int max_length) {
  memset(buffer, 0, max_length);
  buffer[--max_length] = 0;
  buffer[0] = 0;
  char frontname[128];
  char adaptername[128];
  int rc;
  int pos = 0;
  int ifnum = 0;
  while (pos < max_length) {
    sprintf(adaptername, "/dev/dvb/adapter%d", ifnum);
    sprintf(frontname, "%s/frontend0", adaptername);
    int front = open(frontname, O_RDWR);
    if (front == -1 && ifnum == 0)
      return _dvbres_error(res, "Error opening frontend.", errno);
    if (front == -1 && ifnum > 0)
      return _dvbres_ok(res);
    struct dvb_frontend_info finfo;
    rc = ioctl(front, FE_GET_INFO, &finfo);
    if (rc) {
      close(front);
      return _dvbres_error(res, "Rading frontend info", errno);
    }
    rc = close(front);
    if (rc)
      return _dvbres_error(res, "Closing frontend", errno);
    unsigned int i;
    for (i = 0; i < sizeof(finfo.name); i++)
      if (finfo.name[i] == '\t')
        finfo.name[i] = ' ';
    int slen;
    if (ifnum > 0) {
      if (pos >= max_length)
        return _dvbres_error(res, "Device enum buffer too small", -1);
      buffer[pos++] = '\t';
    }
    slen = strlen(finfo.name);
    if (pos + slen >= max_length)
      return _dvbres_error(res, "Device enum buffer too small", -1);
    buffer[pos++] = '0' + ifnum;
    buffer[pos++] = ':';
    buffer[pos++] = ' ';
    strncpy(&buffer[pos], finfo.name, max_length - pos);
    pos += slen;
    if (pos >= max_length)
      return _dvbres_error(res, "Device enum buffer too small", -1);
    buffer[pos++] = '\t';
    slen = strlen(adaptername);
    if (pos + slen >= max_length)
      return _dvbres_error(res, "Device enum buffer too small", -1);
    strncpy(&buffer[pos], adaptername, max_length - pos);
    pos += slen;
    ifnum++;
  }
  return _dvbres_error(res, "Device enum buffer to small", -1);
}


x86 assembly (clang, -O0):
<dvbres_listdevices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    15a2 <dvbres_listdevices+0x412>
lea    -0x120(%rbp),%rdi
mov    -0x12c(%rbp),%edx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0xffffffff,-0x130(%rbp)
jne    127f <dvbres_listdevices+0xef>
cmpl   $0x0,-0x12c(%rbp)
jne    127f <dvbres_listdevices+0xef>
mov    -0x10(%rbp),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
lea    0xdae(%rip),%rsi
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
cmpl   $0xffffffff,-0x130(%rbp)
jne    12aa <dvbres_listdevices+0x11a>
cmpl   $0x0,-0x12c(%rbp)
jle    12aa <dvbres_listdevices+0x11a>
mov    -0x10(%rbp),%rdi
call   1050 <_dvbres_ok@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x130(%rbp),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
lea    -0x138(%rbp),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     1304 <dvbres_listdevices+0x174>
mov    -0x130(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ce2(%rip),%rax
mov    (%rax),%edx
lea    0xd41(%rip),%rsi
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x130(%rbp),%edi
call   1080 <close@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     1343 <dvbres_listdevices+0x1b3>
mov    -0x10(%rbp),%rdi
mov    0x2ca3(%rip),%rax
mov    (%rax),%edx
lea    0xd17(%rip),%rsi
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
movl   $0x0,-0x13c(%rbp)
mov    -0x13c(%rbp),%eax
cmp    $0x8,%rax
jae    13a1 <dvbres_listdevices+0x211>
mov    -0x138(%rbp),%rax
mov    -0x13c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    1388 <dvbres_listdevices+0x1f8>
mov    -0x138(%rbp),%rax
mov    -0x13c(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
jmp    138d <dvbres_listdevices+0x1fd>
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
jmp    134d <dvbres_listdevices+0x1bd>
cmpl   $0x0,-0x12c(%rbp)
jle    13f6 <dvbres_listdevices+0x266>
mov    -0x128(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     13da <dvbres_listdevices+0x24a>
mov    -0x10(%rbp),%rdi
lea    0xc96(%rip),%rsi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x18(%rbp),%rax
mov    -0x128(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x128(%rbp)
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
mov    -0x138(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x140(%rbp)
mov    -0x128(%rbp),%eax
add    -0x140(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     143a <dvbres_listdevices+0x2aa>
mov    -0x10(%rbp),%rdi
lea    0xc36(%rip),%rsi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x12c(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x128(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x128(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x128(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x128(%rbp)
movslq %ecx,%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x128(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x128(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
movslq -0x128(%rbp),%rax
add    %rax,%rdi
mov    -0x138(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    -0x128(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x140(%rbp),%eax
add    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     14f9 <dvbres_listdevices+0x369>
mov    -0x10(%rbp),%rdi
lea    0xb77(%rip),%rsi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x18(%rbp),%rax
mov    -0x128(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x128(%rbp)
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x140(%rbp)
mov    -0x128(%rbp),%eax
add    -0x140(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1559 <dvbres_listdevices+0x3c9>
mov    -0x10(%rbp),%rdi
lea    0xb17(%rip),%rsi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15ba <dvbres_listdevices+0x42a>
mov    -0x18(%rbp),%rdi
movslq -0x128(%rbp),%rax
add    %rax,%rdi
lea    -0x120(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    -0x128(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x140(%rbp),%eax
add    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    11e3 <dvbres_listdevices+0x53>
mov    -0x10(%rbp),%rdi
lea    0xace(%rip),%rsi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbres_listdevices>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
movslq %ebp,%rbp
movb   $0x0,-0x1(%r15,%rbp,1)
movb   $0x0,(%r15)
cmp    $0x2,%ebp
jl     1464 <dvbres_listdevices+0x2d4>
mov    %rbx,0x10(%rsp)
lea    0xe2b(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xe26(%rip),%rsi
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
sete   %al
je     1470 <dvbres_listdevices+0x2e0>
add    $0xffffffffffffffff,%rbp
mov    %rbp,0x18(%rsp)
mov    $0x1,%ebx
xor    %r14d,%r14d
test   $0x1,%al
je     1249 <dvbres_listdevices+0xb9>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%ebx
jne    14af <dvbres_listdevices+0x31f>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
lea    0x8(%rsp),%rdx
call   1070 <ioctl@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1080 <close@plt>
test   %ebp,%ebp
jne    14bb <dvbres_listdevices+0x32b>
test   %eax,%eax
jne    14d2 <dvbres_listdevices+0x342>
mov    0x8(%rsp),%rax
cmpb   $0x9,(%rax)
jne    128b <dvbres_listdevices+0xfb>
movb   $0x20,(%rax)
mov    0x8(%rsp),%rax
mov    0x18(%rsp),%r13
cmpb   $0x9,0x1(%rax)
je     13e0 <dvbres_listdevices+0x250>
cmpb   $0x9,0x2(%rax)
je     13f3 <dvbres_listdevices+0x263>
cmpb   $0x9,0x3(%rax)
je     1406 <dvbres_listdevices+0x276>
cmpb   $0x9,0x4(%rax)
je     1419 <dvbres_listdevices+0x289>
cmpb   $0x9,0x5(%rax)
je     142c <dvbres_listdevices+0x29c>
cmpb   $0x9,0x6(%rax)
je     143f <dvbres_listdevices+0x2af>
cmpb   $0x9,0x7(%rax)
je     1452 <dvbres_listdevices+0x2c2>
cmp    $0x1,%ebx
je     12e7 <dvbres_listdevices+0x157>
movslq %r14d,%rax
add    $0x1,%r14d
movb   $0x9,(%r15,%rax,1)
mov    0x8(%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    (%r14,%rbp,1),%eax
cmp    %r13d,%eax
jge    1487 <dvbres_listdevices+0x2f7>
mov    %rbx,%rax
movslq %r14d,%rbx
mov    %rax,%r12
add    $0x2f,%eax
mov    %al,(%r15,%rbx,1)
movw   $0x203a,0x1(%r15,%rbx,1)
20
lea    0x3(%rbx),%eax
lea    (%r15,%rbx,1),%rdi
add    $0x3,%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
sub    %eax,%edx
call   1030 <strncpy@plt>
add    %ebx,%ebp
add    $0x3,%ebp
cmp    %r13d,%ebp
jge    1487 <dvbres_listdevices+0x2f7>
movslq %ebp,%rax
movb   $0x9,(%r15,%rax,1)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%r14d
add    $0x1,%r14d
cmp    %r13d,%r14d
jge    1487 <dvbres_listdevices+0x2f7>
add    $0x1,%ebp
movslq %ebp,%rax
lea    (%r15,%rax,1),%rdi
mov    %r13d,%edx
sub    %eax,%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
lea    0xc79(%rip),%rsi
mov    %rbx,%r13
mov    %r12,%rbx
mov    %ebx,%edx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
lea    0xc6b(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    0x2c2f(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10a0 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
sete   %al
add    $0x1,%ebx
test   $0x1,%al
jne    1240 <dvbres_listdevices+0xb0>
jmp    1249 <dvbres_listdevices+0xb9>
nopl   0x0(%rax)
movb   $0x20,0x1(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x2(%rax)
jne    12a4 <dvbres_listdevices+0x114>
movb   $0x20,0x2(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x3(%rax)
jne    12ae <dvbres_listdevices+0x11e>
movb   $0x20,0x3(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x4(%rax)
jne    12b8 <dvbres_listdevices+0x128>
movb   $0x20,0x4(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x5(%rax)
jne    12c2 <dvbres_listdevices+0x132>
movb   $0x20,0x5(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x6(%rax)
jne    12cc <dvbres_listdevices+0x13c>
movb   $0x20,0x6(%rax)
mov    0x8(%rsp),%rax
cmpb   $0x9,0x7(%rax)
jne    12d6 <dvbres_listdevices+0x146>
movb   $0x20,0x7(%rax)
cmp    $0x1,%ebx
jne    12db <dvbres_listdevices+0x14b>
jmp    12e7 <dvbres_listdevices+0x157>
lea    0xc10(%rip),%rsi
mov    %rbx,%rdi
jmp    1493 <dvbres_listdevices+0x303>
mov    0x2b59(%rip),%rax
mov    (%rax),%edx
lea    0xba0(%rip),%rsi
mov    0x10(%rsp),%rdi
jmp    1498 <dvbres_listdevices+0x308>
lea    0xbd0(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    $0xffffffff,%edx
call   1090 <_dvbres_error@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
call   1050 <_dvbres_ok@plt>
jmp    149d <dvbres_listdevices+0x30d>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edx
lea    0xb6d(%rip),%rsi
mov    0x10(%rsp),%rdi
jmp    1498 <dvbres_listdevices+0x308>
mov    0x2af7(%rip),%rax
mov    (%rax),%edx
lea    0xb6b(%rip),%rsi
mov    0x10(%rsp),%rdi
jmp    1498 <dvbres_listdevices+0x308>

LLVM IR (-O0):
%struct.dvb_resource = type { i32 }
%struct.dvb_frontend_info = type { i8* }
@.str = [19 x i8] c"/dev/dvb/adapter%d\00"
@.str.1 = [13 x i8] c"%s/frontend0\00"
@O_RDWR = global i32 0
@.str.2 = [24 x i8] c"Error opening frontend.\00"
@errno = global i32 0
@FE_GET_INFO = global i32 0
@.str.3 = [21 x i8] c"Rading frontend info\00"
@.str.4 = [17 x i8] c"Closing frontend\00"
@.str.5 = [29 x i8] c"Device enum buffer too small\00"
@.str.6 = [28 x i8] c"Device enum buffer to small\00"
define i32 @dvbres_listdevices(%struct.dvb_resource* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.dvb_resource*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [128 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.dvb_frontend_info
%15 = alloca i32
%16 = alloca i32
store %struct.dvb_resource* %0, %struct.dvb_resource** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = add nsw i32 %21, -1
store i32 %22, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
store i32 0, i32* %11
store i32 0, i32* %12
br label %27
27: ; preds = %186, %3
%28 = load i32, i32* %11
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %201
31: ; preds = %27
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%33 = load i32, i32* %12
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* @O_RDWR
%40 = call i32 @open(i8* %38, i32 %39)
store i32 %40, i32* %13
%41 = load i32, i32* %13
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %50
43: ; preds = %31
%44 = load i32, i32* %12
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%48 = load i32, i32* @errno
%49 = call i32 @_dvbres_error(%struct.dvb_resource* %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %48)
store i32 %49, i32* %4
br label %204
50: ; preds = %43, %31
%51 = load i32, i32* %13
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32, i32* %12
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%58 = call i32 @_dvbres_ok(%struct.dvb_resource* %57)
store i32 %58, i32* %4
br label %204
59: ; preds = %53, %50
%60 = load i32, i32* %13
%61 = load i32, i32* @FE_GET_INFO
%62 = call i32 @ioctl(i32 %60, i32 %61, %struct.dvb_frontend_info* %14)
store i32 %62, i32* %10
%63 = load i32, i32* %10
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %59
%66 = load i32, i32* %13
%67 = call i32 @close(i32 %66)
%68 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%69 = load i32, i32* @errno
%70 = call i32 @_dvbres_error(%struct.dvb_resource* %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %69)
store i32 %70, i32* %4
br label %204
71: ; preds = %59
%72 = load i32, i32* %13
%73 = call i32 @close(i32 %72)
store i32 %73, i32* %10
%74 = load i32, i32* %10
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %71
%77 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%78 = load i32, i32* @errno
%79 = call i32 @_dvbres_error(%struct.dvb_resource* %77, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %78)
store i32 %79, i32* %4
br label %204
80: ; preds = %71
store i32 0, i32* %15
br label %81
81: ; preds = %101, %80
%82 = load i32, i32* %15
%83 = zext i32 %82 to i64
%84 = icmp ult i64 %83, 8
br i1 %84, label %85, label %104
85: ; preds = %81
%86 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %14, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = load i32, i32* %15
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 9
br i1 %93, label %94, label %100
94: ; preds = %85
%95 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %14, i32 0, i32 0
%96 = load i8*, i8** %95
%97 = load i32, i32* %15
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
store i8 32, i8* %99
br label %100
100: ; preds = %94, %85
br label %101
101: ; preds = %100
%102 = load i32, i32* %15
%103 = add i32 %102, 1
store i32 %103, i32* %15
br label %81
104: ; preds = %81
%105 = load i32, i32* %12
%106 = icmp sgt i32 %105, 0
br i1 %106, label %107, label %120
107: ; preds = %104
%108 = load i32, i32* %11
%109 = load i32, i32* %7
%110 = icmp sge i32 %108, %109
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%113 = call i32 @_dvbres_error(%struct.dvb_resource* %112, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
store i32 %113, i32* %4
br label %204
114: ; preds = %107
%115 = load i8*, i8** %6
%116 = load i32, i32* %11
%117 = add nsw i32 %116, 1
store i32 %117, i32* %11
%118 = sext i32 %116 to i64
%119 = getelementptr inbounds i8, i8* %115, i64 %118
store i8 9, i8* %119
br label %120
120: ; preds = %114, %104
%121 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %14, i32 0, i32 0
%122 = load i8*, i8** %121
%123 = call i32 @strlen(i8* %122)
store i32 %123, i32* %16
%124 = load i32, i32* %11
%125 = load i32, i32* %16
%126 = add nsw i32 %124, %125
%127 = load i32, i32* %7
%128 = icmp sge i32 %126, %127
br i1 %128, label %129, label %132
129: ; preds = %120
%130 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%131 = call i32 @_dvbres_error(%struct.dvb_resource* %130, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
store i32 %131, i32* %4
br label %204
132: ; preds = %120
%133 = load i32, i32* %12
%134 = add nsw i32 48, %133
%135 = trunc i32 %134 to i8
%136 = load i8*, i8** %6
%137 = load i32, i32* %11
%138 = add nsw i32 %137, 1
store i32 %138, i32* %11
%139 = sext i32 %137 to i64
%140 = getelementptr inbounds i8, i8* %136, i64 %139
store i8 %135, i8* %140
%141 = load i8*, i8** %6
%142 = load i32, i32* %11
%143 = add nsw i32 %142, 1
store i32 %143, i32* %11
%144 = sext i32 %142 to i64
%145 = getelementptr inbounds i8, i8* %141, i64 %144
store i8 58, i8* %145
%146 = load i8*, i8** %6
%147 = load i32, i32* %11
%148 = add nsw i32 %147, 1
store i32 %148, i32* %11
%149 = sext i32 %147 to i64
%150 = getelementptr inbounds i8, i8* %146, i64 %149
store i8 32, i8* %150
%151 = load i8*, i8** %6
%152 = load i32, i32* %11
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8, i8* %151, i64 %153
%155 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %14, i32 0, i32 0
%156 = load i8*, i8** %155
%157 = load i32, i32* %7
%158 = load i32, i32* %11
%159 = sub nsw i32 %157, %158
%160 = call i32 @strncpy(i8* %154, i8* %156, i32 %159)
%161 = load i32, i32* %16
%162 = load i32, i32* %11
%163 = add nsw i32 %162, %161
store i32 %163, i32* %11
%164 = load i32, i32* %11
%165 = load i32, i32* %7
%166 = icmp sge i32 %164, %165
br i1 %166, label %167, label %170
167: ; preds = %132
%168 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%169 = call i32 @_dvbres_error(%struct.dvb_resource* %168, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
store i32 %169, i32* %4
br label %204
170: ; preds = %132
%171 = load i8*, i8** %6
%172 = load i32, i32* %11
%173 = add nsw i32 %172, 1
store i32 %173, i32* %11
%174 = sext i32 %172 to i64
%175 = getelementptr inbounds i8, i8* %171, i64 %174
store i8 9, i8* %175
%176 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%177 = call i32 @strlen(i8* %176)
store i32 %177, i32* %16
%178 = load i32, i32* %11
%179 = load i32, i32* %16
%180 = add nsw i32 %178, %179
%181 = load i32, i32* %7
%182 = icmp sge i32 %180, %181
br i1 %182, label %183, label %186
183: ; preds = %170
%184 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%185 = call i32 @_dvbres_error(%struct.dvb_resource* %184, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
store i32 %185, i32* %4
br label %204
186: ; preds = %170
%187 = load i8*, i8** %6
%188 = load i32, i32* %11
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds i8, i8* %187, i64 %189
%191 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%192 = load i32, i32* %7
%193 = load i32, i32* %11
%194 = sub nsw i32 %192, %193
%195 = call i32 @strncpy(i8* %190, i8* %191, i32 %194)
%196 = load i32, i32* %16
%197 = load i32, i32* %11
%198 = add nsw i32 %197, %196
store i32 %198, i32* %11
%199 = load i32, i32* %12
%200 = add nsw i32 %199, 1
store i32 %200, i32* %12
br label %27
201: ; preds = %27
%202 = load %struct.dvb_resource*, %struct.dvb_resource** %5
%203 = call i32 @_dvbres_error(%struct.dvb_resource* %202, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 -1)
store i32 %203, i32* %4
br label %204
204: ; preds = %201, %183, %167, %129, %111, %76, %65, %56, %46
%205 = load i32, i32* %4
ret i32 %205
}

LLVM IR (-O2):
%struct.dvb_resource = type { i32 }
%struct.dvb_frontend_info = type { i8* }
@.str = [19 x i8] c"/dev/dvb/adapter%d\00"
@.str.1 = [13 x i8] c"%s/frontend0\00"
@O_RDWR = global i32 0
@.str.2 = [24 x i8] c"Error opening frontend.\00"
@errno = global i32 0
@FE_GET_INFO = global i32 0
@.str.3 = [21 x i8] c"Rading frontend info\00"
@.str.4 = [17 x i8] c"Closing frontend\00"
@.str.5 = [29 x i8] c"Device enum buffer too small\00"
@.str.6 = [28 x i8] c"Device enum buffer to small\00"
define i32 @dvbres_listdevices(%struct.dvb_resource* %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = alloca %struct.dvb_frontend_info
%7 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%8 = add nsw i32 %2, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
store i8 0, i8* %1
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%13 = icmp sgt i32 %2, 1
br i1 %13, label %14, label %157
14: ; preds = %3
%15 = bitcast %struct.dvb_frontend_info* %6 to i8*
%16 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %6, i64 0, i32 0
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 0)
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* %11, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32, i32* @errno
%24 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %159
25: ; preds = %14, %146
%26 = phi i1 [ %156, %146 ], [ %21, %14 ]
%27 = phi i32 [ %155, %146 ], [ %20, %14 ]
%28 = phi i32 [ %140, %146 ], [ 0, %14 ]
%29 = phi i32 [ %151, %146 ], [ 0, %14 ]
%30 = icmp ne i32 %29, 0
%31 = and i1 %26, %30
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @_dvbres_ok(%struct.dvb_resource* %0)
br label %159
34: ; preds = %25
%35 = load i32, i32* @FE_GET_INFO
%36 = call i32 @ioctl(i32 %27, i32 %35, %struct.dvb_frontend_info* %6)
%37 = icmp eq i32 %36, 0
%38 = call i32 @close(i32 %27)
br i1 %37, label %42, label %39
39: ; preds = %34
%40 = load i32, i32* @errno
%41 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %144
42: ; preds = %34
%43 = icmp eq i32 %38, 0
br i1 %43, label %44, label %48
44: ; preds = %42
%45 = load i8*, i8** %16
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 9
br i1 %47, label %51, label %53
48: ; preds = %42
%49 = load i32, i32* @errno
%50 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %144
51: ; preds = %44
store i8 32, i8* %45
%52 = load i8*, i8** %16
br label %53
53: ; preds = %44, %51
%54 = phi i8* [ %45, %44 ], [ %52, %51 ]
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 9
br i1 %57, label %58, label %60
58: ; preds = %53
store i8 32, i8* %55
%59 = load i8*, i8** %16
br label %60
60: ; preds = %58, %53
%61 = phi i8* [ %59, %58 ], [ %54, %53 ]
%62 = getelementptr inbounds i8, i8* %61, i64 2
%63 = load i8, i8* %62
%64 = icmp eq i8 %63, 9
br i1 %64, label %65, label %67
65: ; preds = %60
store i8 32, i8* %62
%66 = load i8*, i8** %16
br label %67
67: ; preds = %65, %60
%68 = phi i8* [ %66, %65 ], [ %61, %60 ]
%69 = getelementptr inbounds i8, i8* %68, i64 3
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 9
br i1 %71, label %72, label %74
72: ; preds = %67
store i8 32, i8* %69
%73 = load i8*, i8** %16
br label %74
74: ; preds = %72, %67
%75 = phi i8* [ %73, %72 ], [ %68, %67 ]
%76 = getelementptr inbounds i8, i8* %75, i64 4
%77 = load i8, i8* %76
%78 = icmp eq i8 %77, 9
br i1 %78, label %79, label %81
79: ; preds = %74
store i8 32, i8* %76
%80 = load i8*, i8** %16
br label %81
81: ; preds = %79, %74
%82 = phi i8* [ %80, %79 ], [ %75, %74 ]
%83 = getelementptr inbounds i8, i8* %82, i64 5
%84 = load i8, i8* %83
%85 = icmp eq i8 %84, 9
br i1 %85, label %86, label %88
86: ; preds = %81
store i8 32, i8* %83
%87 = load i8*, i8** %16
br label %88
88: ; preds = %86, %81
%89 = phi i8* [ %87, %86 ], [ %82, %81 ]
%90 = getelementptr inbounds i8, i8* %89, i64 6
%91 = load i8, i8* %90
%92 = icmp eq i8 %91, 9
br i1 %92, label %93, label %95
93: ; preds = %88
store i8 32, i8* %90
%94 = load i8*, i8** %16
br label %95
95: ; preds = %93, %88
%96 = phi i8* [ %94, %93 ], [ %89, %88 ]
%97 = getelementptr inbounds i8, i8* %96, i64 7
%98 = load i8, i8* %97
%99 = icmp eq i8 %98, 9
br i1 %99, label %100, label %101
100: ; preds = %95
store i8 32, i8* %97
br label %101
101: ; preds = %100, %95
br i1 %30, label %102, label %106
102: ; preds = %101
%103 = add nsw i32 %28, 1
%104 = sext i32 %28 to i64
%105 = getelementptr inbounds i8, i8* %1, i64 %104
store i8 9, i8* %105
br label %106
106: ; preds = %102, %101
%107 = phi i32 [ %103, %102 ], [ %28, %101 ]
%108 = load i8*, i8** %16
%109 = call i32 @strlen(i8* %108)
%110 = add nsw i32 %109, %107
%111 = icmp slt i32 %110, %8
br i1 %111, label %114, label %112
112: ; preds = %106
%113 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %144
114: ; preds = %106
%115 = trunc i32 %29 to i8
%116 = add i8 %115, 48
%117 = add nsw i32 %107, 1
%118 = sext i32 %107 to i64
%119 = getelementptr inbounds i8, i8* %1, i64 %118
store i8 %116, i8* %119
%120 = add nsw i32 %107, 2
%121 = sext i32 %117 to i64
%122 = getelementptr inbounds i8, i8* %1, i64 %121
store i8 58, i8* %122
%123 = add nsw i32 %107, 3
%124 = sext i32 %120 to i64
%125 = getelementptr inbounds i8, i8* %1, i64 %124
store i8 32, i8* %125
%126 = sext i32 %123 to i64
%127 = getelementptr inbounds i8, i8* %1, i64 %126
%128 = load i8*, i8** %16
%129 = sub nsw i32 %8, %123
%130 = call i32 @strncpy(i8* %127, i8* %128, i32 %129)
%131 = add nsw i32 %109, %123
%132 = icmp slt i32 %131, %8
br i1 %132, label %135, label %133
133: ; preds = %114
%134 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %144
135: ; preds = %114
%136 = add nsw i32 %131, 1
%137 = sext i32 %131 to i64
%138 = getelementptr inbounds i8, i8* %1, i64 %137
store i8 9, i8* %138
%139 = call i32 @strlen(i8* %12)
%140 = add nsw i32 %139, %136
%141 = icmp slt i32 %140, %8
br i1 %141, label %146, label %142
142: ; preds = %135
%143 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %144
144: ; preds = %39, %48, %112, %133, %142
%145 = phi i32 [ %143, %142 ], [ %134, %133 ], [ %113, %112 ], [ %50, %48 ], [ %41, %39 ]
br label %159
146: ; preds = %135
%147 = sext i32 %136 to i64
%148 = getelementptr inbounds i8, i8* %1, i64 %147
%149 = sub nsw i32 %8, %136
%150 = call i32 @strncpy(i8* %148, i8* %12, i32 %149)
%151 = add nuw nsw i32 %29, 1
%152 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %151)
%153 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%154 = load i32, i32* @O_RDWR
%155 = call i32 @open(i8* %11, i32 %154)
%156 = icmp eq i32 %155, -1
br label %25
157: ; preds = %3
%158 = call i32 @_dvbres_error(%struct.dvb_resource* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 -1)
br label %159
159: ; preds = %32, %22, %144, %157
%160 = phi i32 [ %158, %157 ], [ %145, %144 ], [ %33, %32 ], [ %24, %22 ]
ret i32 %160
}