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

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int checkDevice(int, int, int);
int /*<<< orphan*/ printf(char *, int, int);
void checkAllBusesPrint() {
  uint8_t bus;
  uint8_t device;
  uint8_t function;
  uint32_t got;
  uint16_t ven, dev;
  for (bus = 0; bus < 256; bus++) {
    for (device = 0; device < 32; device++) {
      function = 0;
      got = checkDevice(bus, device, function);
      if (got == 0xFFFFFFFF)
        continue;
      dev = (uint16_t)((got >> 16) & 0xffff);
      ven = (uint16_t)((got >> 0) & 0xffff);
      if (got != 0xFFFFFFFF)
        printf("VID: 0x%X DID: 0x%X\n", ven, dev);
      for (function = 1; function < 8; function++) {
        got = checkDevice(bus, device, function);
        dev = (uint16_t)((got >> 16) & 0xffff);
        ven = (uint16_t)((got >> 0) & 0xffff);
        if (got != 0xFFFFFFFF)
          printf("VID: 0x%X DID: 0x%X\n", ven, dev);
      }
    }
  }
}


x86 assembly (clang, -O0):
<checkAllBusesPrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x100,-0x4(%rbp)
jge    123f <checkAllBusesPrint+0x11f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    122c <checkAllBusesPrint+0x10c>
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <checkDevice@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1174 <checkAllBusesPrint+0x54>
jmp    121e <checkAllBusesPrint+0xfe>
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x0,%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     11ac <checkAllBusesPrint+0x8c>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1219 <checkAllBusesPrint+0xf9>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <checkDevice@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
and    $0xffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x0,%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     1206 <checkAllBusesPrint+0xe6>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
jmp    120b <checkAllBusesPrint+0xeb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b3 <checkAllBusesPrint+0x93>
jmp    121e <checkAllBusesPrint+0xfe>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1143 <checkAllBusesPrint+0x23>
jmp    1231 <checkAllBusesPrint+0x111>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112f <checkAllBusesPrint+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkAllBusesPrint>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
lea    0xed3(%rip),%r14
jmp    113f <checkAllBusesPrint+0x1f>
nop
add    $0x1,%ebx
cmp    $0x100,%ebx
je     1276 <checkAllBusesPrint+0x156>
xor    %ebp,%ebp
jmp    1158 <checkAllBusesPrint+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
cmp    $0x20,%ebp
je     1130 <checkAllBusesPrint+0x10>
mov    %ebx,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     1150 <checkAllBusesPrint+0x30>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     119b <checkAllBusesPrint+0x7b>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x2,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     11be <checkAllBusesPrint+0x9e>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x3,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     11e1 <checkAllBusesPrint+0xc1>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x4,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     1204 <checkAllBusesPrint+0xe4>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x5,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     1227 <checkAllBusesPrint+0x107>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x6,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     124a <checkAllBusesPrint+0x12a>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x7,%edx
call   1040 <checkDevice@plt>
cmp    $0xffffffff,%eax
je     1150 <checkAllBusesPrint+0x30>
movzwl %ax,%esi
shr    $0x10,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <printf@plt>
jmp    1150 <checkAllBusesPrint+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"VID: 0x%X DID: 0x%X\0A\00"
define void @checkAllBusesPrint() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %65, %0
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 256
br i1 %9, label %10, label %68
10: ; preds = %7
store i32 0, i32* %2
br label %11
11: ; preds = %61, %10
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 32
br i1 %13, label %14, label %64
14: ; preds = %11
store i32 0, i32* %3
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i32 @checkDevice(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %14
br label %61
22: ; preds = %14
%23 = load i32, i32* %4
%24 = ashr i32 %23, 16
%25 = and i32 %24, 65535
store i32 %25, i32* %6
%26 = load i32, i32* %4
%27 = ashr i32 %26, 0
%28 = and i32 %27, 65535
store i32 %28, i32* %5
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33)
br label %35
35: ; preds = %31, %22
store i32 1, i32* %3
br label %36
36: ; preds = %57, %35
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 8
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = load i32, i32* %1
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = call i32 @checkDevice(i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = ashr i32 %44, 16
%46 = and i32 %45, 65535
store i32 %46, i32* %6
%47 = load i32, i32* %4
%48 = ashr i32 %47, 0
%49 = and i32 %48, 65535
store i32 %49, i32* %5
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %39
%53 = load i32, i32* %5
%54 = load i32, i32* %6
%55 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %53, i32 %54)
br label %56
56: ; preds = %52, %39
br label %57
57: ; preds = %56
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
br label %36
60: ; preds = %36
br label %61
61: ; preds = %60, %21
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
store i32 %63, i32* %2
br label %11
64: ; preds = %11
br label %65
65: ; preds = %64
%66 = load i32, i32* %1
%67 = add nsw i32 %66, 1
store i32 %67, i32* %1
br label %7
68: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"VID: 0x%X DID: 0x%X\0A\00"
define void @checkAllBusesPrint() {
br label %1
1: ; preds = %0, %62
%2 = phi i32 [ 0, %0 ], [ %63, %62 ]
br label %3
3: ; preds = %1, %59
%4 = phi i32 [ 0, %1 ], [ %60, %59 ]
%5 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %59, label %7
7: ; preds = %3
%8 = and i32 %5, 65535
%9 = lshr i32 %5, 16
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = and i32 %11, 65535
%15 = lshr i32 %11, 16
%16 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
br label %17
17: ; preds = %7, %13
%18 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 2)
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = and i32 %18, 65535
%22 = lshr i32 %18, 16
%23 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %20, %17
%25 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = and i32 %25, 65535
%29 = lshr i32 %25, 16
%30 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %27, %24
%32 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = and i32 %32, 65535
%36 = lshr i32 %32, 16
%37 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
br label %38
38: ; preds = %34, %31
%39 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 5)
%40 = icmp eq i32 %39, -1
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = and i32 %39, 65535
%43 = lshr i32 %39, 16
%44 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %43)
br label %45
45: ; preds = %41, %38
%46 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 6)
%47 = icmp eq i32 %46, -1
br i1 %47, label %52, label %48
48: ; preds = %45
%49 = and i32 %46, 65535
%50 = lshr i32 %46, 16
%51 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %48, %45
%53 = tail call i32 @checkDevice(i32 %2, i32 %4, i32 7)
%54 = icmp eq i32 %53, -1
br i1 %54, label %59, label %55
55: ; preds = %52
%56 = and i32 %53, 65535
%57 = lshr i32 %53, 16
%58 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %56, i32 %57)
br label %59
59: ; preds = %52, %55, %3
%60 = add nuw nsw i32 %4, 1
%61 = icmp eq i32 %60, 32
br i1 %61, label %62, label %3
62: ; preds = %59
%63 = add nuw nsw i32 %2, 1
%64 = icmp eq i32 %63, 256
br i1 %64, label %65, label %1
65: ; preds = %62
ret void
}