#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 scalar_t__ cnt_base;

/* Variables and functions */
scalar_t__ is_Master_cpu();
unsigned int _DS_bus_to_phy_addr(unsigned int bus_addr) {
  unsigned int *p_offset_reg, *p_max_reg;
  unsigned int phy_addr;
  unsigned int cnt_base;
  if (is_Master_cpu()) {
    cnt_base = (0xB8001700);
  } else {
    cnt_base = (0xB8001700) + 0x40;
  }
  if ((((unsigned int)(0x00000000)) <= bus_addr) &&
      (((unsigned int)(0x10000000)) > bus_addr)) {
    p_offset_reg = (unsigned int *)(cnt_base);
    p_max_reg = (unsigned int *)(cnt_base + 0x4);
    if (*p_max_reg < bus_addr)
      phy_addr = 0xFFFFFFFF;
    else
      phy_addr = bus_addr + (*p_offset_reg);
  } else if ((((unsigned int)(0x10000000)) <= bus_addr) &&
             (((unsigned int)(0x20000000)) > bus_addr)) {
    p_offset_reg = (unsigned int *)(cnt_base + 0x10);
    p_max_reg = (unsigned int *)((cnt_base) + 0x14);
    if (*p_max_reg < bus_addr)
      phy_addr = 0xFFFFFFFF;
    else
      phy_addr = bus_addr + (*p_offset_reg);
  } else if ((((unsigned int)(0x20000000)) <= bus_addr) &&
             (((unsigned int)(0x7FFFFFFF)) >= bus_addr)) {
    p_offset_reg = (unsigned int *)(cnt_base + 0x20);
    p_max_reg = (unsigned int *)(cnt_base + 0x24);
    if (*p_max_reg < bus_addr)
      phy_addr = 0xFFFFFFFF;
    else
      phy_addr = bus_addr + (*p_offset_reg);
  } else {
    phy_addr = 0xFFFFFFFF;
  }
  return phy_addr;
}


x86 assembly (clang, -O0):
<_DS_bus_to_phy_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <is_Master_cpu@plt>
cmp    $0x0,%rax
je     1138 <_DS_bus_to_phy_addr+0x28>
movl   $0xb8001700,-0x20(%rbp)
jmp    113f <_DS_bus_to_phy_addr+0x2f>
movl   $0xb8001740,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x4(%rbp),%eax
ja     1197 <_DS_bus_to_phy_addr+0x87>
mov    $0x10000000,%eax
cmp    -0x4(%rbp),%eax
jbe    1197 <_DS_bus_to_phy_addr+0x87>
mov    -0x20(%rbp),%eax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jae    1186 <_DS_bus_to_phy_addr+0x76>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1192 <_DS_bus_to_phy_addr+0x82>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    1268 <_DS_bus_to_phy_addr+0x158>
mov    $0x10000000,%eax
cmp    -0x4(%rbp),%eax
ja     11f7 <_DS_bus_to_phy_addr+0xe7>
mov    $0x20000000,%eax
cmp    -0x4(%rbp),%eax
jbe    11f7 <_DS_bus_to_phy_addr+0xe7>
mov    -0x20(%rbp),%eax
add    $0x10,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x14,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jae    11e6 <_DS_bus_to_phy_addr+0xd6>
movl   $0xffffffff,-0x1c(%rbp)
jmp    11f2 <_DS_bus_to_phy_addr+0xe2>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    1263 <_DS_bus_to_phy_addr+0x153>
mov    $0x20000000,%eax
cmp    -0x4(%rbp),%eax
ja     1257 <_DS_bus_to_phy_addr+0x147>
mov    $0x7fffffff,%eax
cmp    -0x4(%rbp),%eax
jb     1257 <_DS_bus_to_phy_addr+0x147>
mov    -0x20(%rbp),%eax
add    $0x20,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x24,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jae    1246 <_DS_bus_to_phy_addr+0x136>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1252 <_DS_bus_to_phy_addr+0x142>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    125e <_DS_bus_to_phy_addr+0x14e>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1263 <_DS_bus_to_phy_addr+0x153>
jmp    1268 <_DS_bus_to_phy_addr+0x158>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DS_bus_to_phy_addr>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <is_Master_cpu@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
shl    $0x6,%ecx
or     $0xb8001700,%ecx
cmp    $0xfffffff,%ebx
ja     1147 <_DS_bus_to_phy_addr+0x37>
mov    %ecx,%ecx
mov    %rcx,%rdx
or     $0x4,%rdx
mov    $0xffffffff,%eax
cmp    %ebx,(%rdx)
jae    1181 <_DS_bus_to_phy_addr+0x71>
pop    %rbx
ret
cmp    $0x1fffffff,%ebx
ja     1167 <_DS_bus_to_phy_addr+0x57>
mov    %ecx,%ecx
mov    %rcx,%rdx
or     $0x14,%rdx
mov    $0xffffffff,%eax
cmp    %ebx,(%rdx)
jb     1145 <_DS_bus_to_phy_addr+0x35>
or     $0x10,%rcx
jmp    1181 <_DS_bus_to_phy_addr+0x71>
mov    $0xffffffff,%eax
test   %ebx,%ebx
js     1145 <_DS_bus_to_phy_addr+0x35>
mov    %ecx,%ecx
mov    %rcx,%rdx
or     $0x24,%rdx
cmp    %ebx,(%rdx)
jb     1145 <_DS_bus_to_phy_addr+0x35>
or     $0x20,%rcx
add    (%rcx),%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_DS_bus_to_phy_addr(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i64 (...) @is_Master_cpu()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1207953664, i32* %6
br label %11
10: ; preds = %1
store i32 -1207953600, i32* %6
br label %11
11: ; preds = %10, %9
%12 = load i32, i32* %2
%13 = icmp ule i32 0, %12
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp ugt i32 268435456, %15
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %3
%21 = load i32, i32* %6
%22 = add i32 %21, 4
%23 = zext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %4
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = load i32, i32* %2
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %17
store i32 -1, i32* %5
br label %35
30: ; preds = %17
%31 = load i32, i32* %2
%32 = load i32*, i32** %3
%33 = load i32, i32* %32
%34 = add i32 %31, %33
store i32 %34, i32* %5
br label %35
35: ; preds = %30, %29
br label %91
36: ; preds = %14, %11
%37 = load i32, i32* %2
%38 = icmp ule i32 268435456, %37
br i1 %38, label %39, label %62
39: ; preds = %36
%40 = load i32, i32* %2
%41 = icmp ugt i32 536870912, %40
br i1 %41, label %42, label %62
42: ; preds = %39
%43 = load i32, i32* %6
%44 = add i32 %43, 16
%45 = zext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
store i32* %46, i32** %3
%47 = load i32, i32* %6
%48 = add i32 %47, 20
%49 = zext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
store i32* %50, i32** %4
%51 = load i32*, i32** %4
%52 = load i32, i32* %51
%53 = load i32, i32* %2
%54 = icmp ult i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %42
store i32 -1, i32* %5
br label %61
56: ; preds = %42
%57 = load i32, i32* %2
%58 = load i32*, i32** %3
%59 = load i32, i32* %58
%60 = add i32 %57, %59
store i32 %60, i32* %5
br label %61
61: ; preds = %56, %55
br label %90
62: ; preds = %39, %36
%63 = load i32, i32* %2
%64 = icmp ule i32 536870912, %63
br i1 %64, label %65, label %88
65: ; preds = %62
%66 = load i32, i32* %2
%67 = icmp uge i32 2147483647, %66
br i1 %67, label %68, label %88
68: ; preds = %65
%69 = load i32, i32* %6
%70 = add i32 %69, 32
%71 = zext i32 %70 to i64
%72 = inttoptr i64 %71 to i32*
store i32* %72, i32** %3
%73 = load i32, i32* %6
%74 = add i32 %73, 36
%75 = zext i32 %74 to i64
%76 = inttoptr i64 %75 to i32*
store i32* %76, i32** %4
%77 = load i32*, i32** %4
%78 = load i32, i32* %77
%79 = load i32, i32* %2
%80 = icmp ult i32 %78, %79
br i1 %80, label %81, label %82
81: ; preds = %68
store i32 -1, i32* %5
br label %87
82: ; preds = %68
%83 = load i32, i32* %2
%84 = load i32*, i32** %3
%85 = load i32, i32* %84
%86 = add i32 %83, %85
store i32 %86, i32* %5
br label %87
87: ; preds = %82, %81
br label %89
88: ; preds = %65, %62
store i32 -1, i32* %5
br label %89
89: ; preds = %88, %87
br label %90
90: ; preds = %89, %61
br label %91
91: ; preds = %90, %35
%92 = load i32, i32* %5
ret i32 %92
}

LLVM IR (-O2):
define i32 @_DS_bus_to_phy_addr(i32 %0) {
%2 = tail call i64 (...) @is_Master_cpu()
%3 = icmp eq i64 %2, 0
%4 = select i1 %3, i32 -1207953600, i32 -1207953664
%5 = icmp ult i32 %0, 268435456
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = or i32 %4, 4
%8 = zext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* %9
%11 = icmp ult i32 %10, %0
br i1 %11, label %45, label %12
12: ; preds = %6
%13 = zext i32 %4 to i64
%14 = inttoptr i64 %13 to i32*
%15 = load i32, i32* %14
%16 = add i32 %15, %0
br label %45
17: ; preds = %1
%18 = icmp ult i32 %0, 536870912
br i1 %18, label %19, label %31
19: ; preds = %17
%20 = or i32 %4, 20
%21 = zext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
%23 = load i32, i32* %22
%24 = icmp ult i32 %23, %0
br i1 %24, label %45, label %25
25: ; preds = %19
%26 = or i32 %4, 16
%27 = zext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = load i32, i32* %28
%30 = add i32 %29, %0
br label %45
31: ; preds = %17
%32 = icmp sgt i32 %0, -1
br i1 %32, label %33, label %45
33: ; preds = %31
%34 = or i32 %4, 36
%35 = zext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
%37 = load i32, i32* %36
%38 = icmp ult i32 %37, %0
br i1 %38, label %45, label %39
39: ; preds = %33
%40 = or i32 %4, 32
%41 = zext i32 %40 to i64
%42 = inttoptr i64 %41 to i32*
%43 = load i32, i32* %42
%44 = add i32 %43, %0
br label %45
45: ; preds = %31, %33, %19, %6, %25, %39, %12
%46 = phi i32 [ %16, %12 ], [ %30, %25 ], [ %44, %39 ], [ -1, %6 ], [ -1, %19 ], [ -1, %33 ], [ -1, %31 ]
ret i32 %46
}