#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;
  char type;
};

/* Variables and functions */
int /*<<< orphan*/ FE_GET_INFO;
int /*<<< orphan*/ O_RDWR;
int _dvbres_error(struct dvb_resource *, char *, int);
int _dvbres_ok_retval(struct dvb_resource *, int);
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);
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[32];
  char adaptername[32];
  int rc;
  int pos = 0;
  int ifnum = 0;
  while (pos < max_length) {
    sprintf(adaptername, "/dev/dvb/adapter%d", ifnum);
    sprintf(frontname, "/dev/dvb/adapter%d/frontend0", ifnum);
    int front = open(frontname, O_RDWR);
    if (front == -1)
      return _dvbres_ok_retval(res, pos);
    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);
    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;
    if (pos + 1 >= max_length)
      return _dvbres_error(res, "Device enum buffer too small", -1);
    buffer[pos++] = '\t';
    buffer[pos++] = '0' + finfo.type;
    ifnum++;
  }
  return _dvbres_error(res, "Device enum buffer to small", -1);
}


x86 assembly (clang, -O0):
<dvbres_listdevices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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   1050 <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,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    14d9 <dvbres_listdevices+0x349>
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%edx
lea    0xe09(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x6c(%rbp),%edx
lea    0xe09(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0xffffffff,-0x70(%rbp)
jne    1242 <dvbres_listdevices+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1090 <_dvbres_ok_retval@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x70(%rbp),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     128d <dvbres_listdevices+0xfd>
mov    -0x70(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
lea    0xdb0(%rip),%rsi
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x70(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     12c3 <dvbres_listdevices+0x133>
mov    -0x10(%rbp),%rdi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
lea    0xd8f(%rip),%rsi
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    $0x8,%rax
jae    131b <dvbres_listdevices+0x18b>
mov    -0x80(%rbp),%rax
mov    -0x84(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    1302 <dvbres_listdevices+0x172>
mov    -0x80(%rbp),%rax
mov    -0x84(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
jmp    1307 <dvbres_listdevices+0x177>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12cd <dvbres_listdevices+0x13d>
cmpl   $0x0,-0x6c(%rbp)
jle    1364 <dvbres_listdevices+0x1d4>
mov    -0x68(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     134e <dvbres_listdevices+0x1be>
mov    -0x10(%rbp),%rdi
lea    0xd1a(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x18(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x68(%rbp)
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
mov    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x88(%rbp)
mov    -0x68(%rbp),%eax
add    -0x88(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     13a2 <dvbres_listdevices+0x212>
mov    -0x10(%rbp),%rdi
lea    0xcc6(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x18(%rbp),%rdi
movslq -0x68(%rbp),%rax
add    %rax,%rdi
mov    -0x80(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    -0x68(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x88(%rbp),%eax
add    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     13f1 <dvbres_listdevices+0x261>
mov    -0x10(%rbp),%rdi
lea    0xc77(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x18(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x68(%rbp)
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x88(%rbp)
mov    -0x68(%rbp),%eax
add    -0x88(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1445 <dvbres_listdevices+0x2b5>
mov    -0x10(%rbp),%rdi
lea    0xc23(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x18(%rbp),%rdi
movslq -0x68(%rbp),%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    -0x68(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x88(%rbp),%eax
add    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jl     1497 <dvbres_listdevices+0x307>
mov    -0x10(%rbp),%rdi
lea    0xbd1(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
jmp    14f1 <dvbres_listdevices+0x361>
mov    -0x18(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x68(%rbp)
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
movsbl -0x78(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x68(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11dd <dvbres_listdevices+0x4d>
mov    -0x10(%rbp),%rdi
lea    0xb8f(%rip),%rsi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvbres_listdevices>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,(%rsp)
xor    %ebp,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movslq %r14d,%r12
movb   $0x0,-0x1(%rbx,%r12,1)
movb   $0x0,(%rbx)
cmp    $0x2,%r12d
jl     1403 <dvbres_listdevices+0x273>
mov    %rbx,%r14
add    $0xffffffffffffffff,%r12
lea    0x20(%rsp),%rbx
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %rbx,%r15
mov    %rbx,%rdi
lea    0xe13(%rip),%rsi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
lea    0xe10(%rip),%rsi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1430 <dvbres_listdevices+0x2a0>
mov    %eax,%ebx
mov    %ebp,0xc(%rsp)
mov    %r14,%rbp
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x10(%rsp),%rdx
call   1060 <ioctl@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1070 <close@plt>
test   %r14d,%r14d
jne    143e <dvbres_listdevices+0x2ae>
test   %eax,%eax
jne    1454 <dvbres_listdevices+0x2c4>
mov    0x10(%rsp),%rax
cmpb   $0x9,(%rax)
jne    126f <dvbres_listdevices+0xdf>
movb   $0x20,(%rax)
mov    0x10(%rsp),%rax
mov    %r15,%rbx
mov    0xc(%rsp),%ecx
cmpb   $0x9,0x1(%rax)
je     1380 <dvbres_listdevices+0x1f0>
cmpb   $0x9,0x2(%rax)
je     1393 <dvbres_listdevices+0x203>
cmpb   $0x9,0x3(%rax)
je     13a6 <dvbres_listdevices+0x216>
cmpb   $0x9,0x4(%rax)
je     13b9 <dvbres_listdevices+0x229>
cmpb   $0x9,0x5(%rax)
je     13cc <dvbres_listdevices+0x23c>
cmpb   $0x9,0x6(%rax)
je     13df <dvbres_listdevices+0x24f>
cmpb   $0x9,0x7(%rax)
je     13f2 <dvbres_listdevices+0x262>
test   %ecx,%ecx
je     12cc <dvbres_listdevices+0x13c>
movslq %r13d,%rax
add    $0x1,%r13d
movb   $0x9,0x0(%rbp,%rax,1)
mov    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
add    %r13d,%r14d
cmp    %r12d,%r14d
jge    140c <dvbres_listdevices+0x27c>
movslq %r13d,%rax
lea    (%rax,%rbp,1),%rdi
mov    0x10(%rsp),%rsi
mov    %r12d,%edx
sub    %eax,%edx
call   1030 <strncpy@plt>
movslq %r14d,%rax
movb   $0x9,0x0(%rbp,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r14,1),%r13d
add    $0x1,%r13d
cmp    %r12d,%r13d
jge    140c <dvbres_listdevices+0x27c>
add    $0x1,%r14d
movslq %r14d,%rax
lea    (%rax,%rbp,1),%rdi
mov    %r12d,%edx
sub    %eax,%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
movslq %r13d,%rcx
lea    0x1(%rcx),%rax
cmp    %r12d,%eax
jge    140c <dvbres_listdevices+0x27c>
movb   $0x9,0x0(%rbp,%rcx,1)
movzbl 0x18(%rsp),%ecx
add    $0x30,%cl
add    $0x2,%r13d
mov    %rbp,%r14
mov    %cl,0x0(%rbp,%rax,1)
mov    0xc(%rsp),%ebp
add    $0x1,%ebp
cmp    %r12d,%r13d
jl     11e0 <dvbres_listdevices+0x50>
jmp    1403 <dvbres_listdevices+0x273>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x20,0x1(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x2(%rax)
jne    128a <dvbres_listdevices+0xfa>
movb   $0x20,0x2(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x3(%rax)
jne    1294 <dvbres_listdevices+0x104>
movb   $0x20,0x3(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x4(%rax)
jne    129e <dvbres_listdevices+0x10e>
movb   $0x20,0x4(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x5(%rax)
jne    12a8 <dvbres_listdevices+0x118>
movb   $0x20,0x5(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x6(%rax)
jne    12b2 <dvbres_listdevices+0x122>
movb   $0x20,0x6(%rax)
mov    0x10(%rsp),%rax
cmpb   $0x9,0x7(%rax)
jne    12bc <dvbres_listdevices+0x12c>
movb   $0x20,0x7(%rax)
test   %ecx,%ecx
jne    12c0 <dvbres_listdevices+0x130>
jmp    12cc <dvbres_listdevices+0x13c>
lea    0xc69(%rip),%rsi
jmp    1413 <dvbres_listdevices+0x283>
lea    0xc43(%rip),%rsi
mov    (%rsp),%rdi
mov    $0xffffffff,%edx
call   1080 <_dvbres_error@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rdi
mov    %r13d,%esi
call   1090 <_dvbres_ok_retval@plt>
jmp    1421 <dvbres_listdevices+0x291>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edx
lea    0xbe2(%rip),%rsi
mov    (%rsp),%rdi
jmp    141c <dvbres_listdevices+0x28c>
mov    0x2b75(%rip),%rax
mov    (%rax),%edx
lea    0xbe1(%rip),%rsi
mov    (%rsp),%rdi
jmp    141c <dvbres_listdevices+0x28c>

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

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