#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 */

/* Variables and functions */
int /*<<< orphan*/ dt_xlate_reg(void *, int, unsigned long *,
                                int /*<<< orphan*/ *);
int getprop(void *, char *, void **, int);
int dt_get_virtual_reg(void *node, void **addr, int nres) {
  unsigned long xaddr;
  int n;
  n = getprop(node, "virtual-reg", addr, nres * 4);
  if (n > 0)
    return n / 4;
  for (n = 0; n < nres; n++) {
    if (!dt_xlate_reg(node, n, &xaddr, NULL))
      break;
    addr[n] = (void *)xaddr;
  }
  return n;
}


x86 assembly (clang, -O0):
<dt_get_virtual_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
lea    0xeb8(%rip),%rsi
call   1040 <getprop@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    116d <dt_get_virtual_reg+0x4d>
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    11c6 <dt_get_virtual_reg+0xa6>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c0 <dt_get_virtual_reg+0xa0>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <dt_xlate_reg@plt>
cmp    $0x0,%eax
jne    11a2 <dt_get_virtual_reg+0x82>
jmp    11c0 <dt_get_virtual_reg+0xa0>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1174 <dt_get_virtual_reg+0x54>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dt_get_virtual_reg>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%r12,4),%ecx
lea    0xebb(%rip),%rsi
mov    %r14,%rdx
call   1040 <getprop@plt>
test   %eax,%eax
jle    1166 <dt_get_virtual_reg+0x46>
mov    %eax,%ebx
shr    $0x2,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
test   %r12d,%r12d
jle    11aa <dt_get_virtual_reg+0x8a>
mov    %r12d,%r13d
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1030 <dt_xlate_reg@plt>
test   %eax,%eax
je     1156 <dt_get_virtual_reg+0x36>
mov    0x8(%rsp),%rax
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <dt_get_virtual_reg+0x60>
mov    %r13d,%ebx
jmp    1156 <dt_get_virtual_reg+0x36>
xor    %ebx,%ebx
jmp    1156 <dt_get_virtual_reg+0x36>

LLVM IR (-O0):
@.str = [12 x i8] c"virtual-reg\00"
define i32 @dt_get_virtual_reg(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i8**, i8*** %6
%12 = load i32, i32* %7
%13 = mul nsw i32 %12, 4
%14 = call i32 @getprop(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %11, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %9
%19 = sdiv i32 %18, 4
store i32 %19, i32* %4
br label %43
20: ; preds = %3
store i32 0, i32* %9
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i32, i32* %9
%28 = call i32 @dt_xlate_reg(i8* %26, i32 %27, i64* %8, i32* null)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
br label %41
31: ; preds = %25
%32 = load i64, i64* %8
%33 = inttoptr i64 %32 to i8*
%34 = load i8**, i8*** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
store i8* %33, i8** %37
br label %38
38: ; preds = %31
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %21
41: ; preds = %30, %21
%42 = load i32, i32* %9
store i32 %42, i32* %4
br label %43
43: ; preds = %41, %17
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [12 x i8] c"virtual-reg\00"
define i32 @dt_get_virtual_reg(i8* %0, i8** %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = shl nsw i32 %2, 2
%7 = tail call i32 @getprop(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %1, i32 %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %28
11: ; preds = %9
%12 = zext i32 %2 to i64
br label %15
13: ; preds = %3
%14 = lshr i32 %7, 2
br label %28
15: ; preds = %11, %20
%16 = phi i64 [ 0, %11 ], [ %24, %20 ]
%17 = trunc i64 %16 to i32
%18 = call i32 @dt_xlate_reg(i8* %0, i32 %17, i64* %4, i32* null)
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = load i64, i64* %4
%22 = inttoptr i64 %21 to i8*
%23 = getelementptr inbounds i8*, i8** %1, i64 %16
store i8* %22, i8** %23
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %28, label %15
26: ; preds = %15
%27 = trunc i64 %16 to i32
br label %28
28: ; preds = %20, %26, %9, %13
%29 = phi i32 [ %14, %13 ], [ 0, %9 ], [ %27, %26 ], [ %2, %20 ]
ret i32 %29
}