#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 dtree_dev_t {
  int dummy;
};

/* Variables and functions */
int dtree_dev_base(struct dtree_dev_t *);
char **dtree_dev_compat(struct dtree_dev_t *);
int /*<<< orphan*/ dtree_dev_free(struct dtree_dev_t *);
int dtree_dev_high(struct dtree_dev_t *);
char *dtree_dev_name(struct dtree_dev_t *);
char *dtree_errstr();
scalar_t__ dtree_iserror();
struct dtree_dev_t *dtree_next();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void bus_list(void) {
  struct dtree_dev_t *dev;
  while ((dev = dtree_next()) != NULL) {
    printf("%s", dtree_dev_name(dev));
    printf(" at 0x%X..0x%X", dtree_dev_base(dev), dtree_dev_high(dev));
    const char **compat = dtree_dev_compat(dev);
    if (compat[0] != NULL)
      printf(" [");
    for (size_t i = 0; compat[i] != NULL; ++i)
      printf("%s%s", compat[i], compat[i + 1] == NULL ? "]" : ", ");
    printf("\n");
    dtree_dev_free(dev);
  }
  if (dtree_iserror())
    fprintf(stderr, "Error: %s\n", dtree_errstr());
}


x86 assembly (clang, -O0):
<bus_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1080 <dtree_next@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     12ad <bus_list+0x10d>
mov    -0x8(%rbp),%rdi
call   1040 <dtree_dev_name@plt>
mov    %rax,%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <dtree_dev_base@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <dtree_dev_high@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <dtree_dev_compat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1228 <bus_list+0x88>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1291 <bus_list+0xf1>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rcx
lea    0xdb6(%rip),%rdx
lea    0xdad(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rdx
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1230 <bus_list+0x90>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <dtree_dev_free@plt>
jmp    11a8 <bus_list+0x8>
mov    $0x0,%al
call   10a0 <dtree_iserror@plt>
cmp    $0x0,%rax
je     12e3 <bus_list+0x143>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <dtree_errstr@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xd3e(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bus_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <dtree_next@plt>
test   %rax,%rax
je     12a8 <bus_list+0xf8>
mov    %rax,%rbx
lea    0xe2b(%rip),%r15
lea    0xe3b(%rip),%r12
lea    0xe36(%rip),%r14
lea    0xe28(%rip),%r13
jmp    1215 <bus_list+0x65>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   10d0 <dtree_dev_free@plt>
xor    %eax,%eax
call   1090 <dtree_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12a8 <bus_list+0xf8>
mov    %rbx,%rdi
call   1050 <dtree_dev_name@plt>
lea    0xdf0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <dtree_dev_base@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10a0 <dtree_dev_high@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <dtree_dev_compat@plt>
cmpq   $0x0,(%rax)
je     11f0 <bus_list+0x40>
mov    %rax,%rbp
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     11f0 <bus_list+0x40>
add    $0x8,%rbp
xchg   %ax,%ax
cmpq   $0x0,0x0(%rbp)
mov    %r14,%rdx
cmove  %r12,%rdx
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1280 <bus_list+0xd0>
jmp    11f0 <bus_list+0x40>
xor    %eax,%eax
call   10b0 <dtree_iserror@plt>
test   %rax,%rax
je     12e3 <bus_list+0x133>
mov    0x2d25(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <dtree_errstr@plt>
lea    0xd51(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dtree_dev_t = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [15 x i8] c" at 0x%X..0x%X\00"
@.str.2 = [3 x i8] c" [\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [2 x i8] c"]\00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.7 = [11 x i8] c"Error: %s\0A\00"
define void @bus_list() {
%1 = alloca %struct.dtree_dev_t*
%2 = alloca i8**
%3 = alloca i64
br label %4
4: ; preds = %48, %0
%5 = call %struct.dtree_dev_t* (...) @dtree_next()
store %struct.dtree_dev_t* %5, %struct.dtree_dev_t** %1
%6 = icmp ne %struct.dtree_dev_t* %5, null
br i1 %6, label %7, label %52
7: ; preds = %4
%8 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %1
%9 = call i8* @dtree_dev_name(%struct.dtree_dev_t* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %1
%12 = call i32 @dtree_dev_base(%struct.dtree_dev_t* %11)
%13 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %1
%14 = call i32 @dtree_dev_high(%struct.dtree_dev_t* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
%16 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %1
%17 = call i8** @dtree_dev_compat(%struct.dtree_dev_t* %16)
store i8** %17, i8*** %2
%18 = load i8**, i8*** %2
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %7
store i64 0, i64* %3
br label %25
25: ; preds = %45, %24
%26 = load i8**, i8*** %2
%27 = load i64, i64* %3
%28 = getelementptr inbounds i8*, i8** %26, i64 %27
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %48
31: ; preds = %25
%32 = load i8**, i8*** %2
%33 = load i64, i64* %3
%34 = getelementptr inbounds i8*, i8** %32, i64 %33
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %2
%37 = load i64, i64* %3
%38 = add i64 %37, 1
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %43)
br label %45
45: ; preds = %31
%46 = load i64, i64* %3
%47 = add i64 %46, 1
store i64 %47, i64* %3
br label %25
48: ; preds = %25
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%50 = load %struct.dtree_dev_t*, %struct.dtree_dev_t** %1
%51 = call i32 @dtree_dev_free(%struct.dtree_dev_t* %50)
br label %4
52: ; preds = %4
%53 = call i64 (...) @dtree_iserror()
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i8* (...) @dtree_errstr()
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %55, %52
ret void
}

LLVM IR (-O2):
%struct.dtree_dev_t = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [15 x i8] c" at 0x%X..0x%X\00"
@.str.2 = [3 x i8] c" [\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [2 x i8] c"]\00"
@.str.5 = [3 x i8] c", \00"
@stderr = global i32 0
@.str.7 = [11 x i8] c"Error: %s\0A\00"
define void @bus_list() {
%1 = tail call %struct.dtree_dev_t* (...) @dtree_next()
%2 = icmp eq %struct.dtree_dev_t* %1, null
br i1 %2, label %33, label %3
3: ; preds = %0, %17
%4 = phi %struct.dtree_dev_t* [ %20, %17 ], [ %1, %0 ]
%5 = tail call i8* @dtree_dev_name(%struct.dtree_dev_t* %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @dtree_dev_base(%struct.dtree_dev_t* %4)
%8 = tail call i32 @dtree_dev_high(%struct.dtree_dev_t* %4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
%10 = tail call i8** @dtree_dev_compat(%struct.dtree_dev_t* %4)
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %10
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %22, %3, %13
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @dtree_dev_free(%struct.dtree_dev_t* %4)
%20 = tail call %struct.dtree_dev_t* (...) @dtree_next()
%21 = icmp eq %struct.dtree_dev_t* %20, null
br i1 %21, label %33, label %3
22: ; preds = %13, %22
%23 = phi i8* [ %31, %22 ], [ %15, %13 ]
%24 = phi i64 [ %25, %22 ], [ 0, %13 ]
%25 = add i64 %24, 1
%26 = getelementptr inbounds i8*, i8** %10, i64 %25
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
%29 = select i1 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %29)
%31 = load i8*, i8** %26
%32 = icmp eq i8* %31, null
br i1 %32, label %17, label %22
33: ; preds = %17, %0
%34 = tail call i64 (...) @dtree_iserror()
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i8* (...) @dtree_errstr()
%39 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %33
ret void
}