#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 */
unsigned int __builtin_inl(int);
int /*<<< orphan*/ __builtin_outl(unsigned long, int);
void order_dimms(void) {
  unsigned long tom;
  tom = 0;
  for (;;) {
    unsigned csbase, csmask;
    unsigned size;
    unsigned index;
    csbase = 0;
    for (index = 0; index < 1; index++) {
      csbase = __builtin_inl(0x40);
    }
    if (csbase == 0) {
      break;
    }
    size = csbase;
    csbase = (tom << 21);
    tom += size;
    csmask = size;
    csmask |= 0xfe00;
    __builtin_outl(csbase, 0xCFC);
    __builtin_outl(0xc260, 0xCF8);
    __builtin_outl(csmask, 0xCFC);
  }
  tom &= ~0xff000000;
  __builtin_outl(tom, 0x1234);
}


x86 assembly (clang, -O0):
<order_dimms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jae    1163 <order_dimms+0x43>
mov    $0x40,%edi
call   1030 <__builtin_inl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <order_dimms+0x1e>
cmpl   $0x0,-0xc(%rbp)
jne    1172 <order_dimms+0x52>
jmp    11d1 <order_dimms+0xb1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x15,%rax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
or     $0xfe00,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%edi
mov    $0xcfc,%esi
call   1040 <__builtin_outl@plt>
mov    $0xc260,%edi
mov    $0xcf8,%esi
call   1040 <__builtin_outl@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%edi
mov    $0xcfc,%esi
call   1040 <__builtin_outl@plt>
jmp    1130 <order_dimms+0x10>
mov    -0x8(%rbp),%rax
and    $0xffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1234,%esi
call   1040 <__builtin_outl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<order_dimms>:
push   %r14
push   %rbx
push   %rax
mov    $0x40,%edi
call   1030 <__builtin_inl@plt>
test   %eax,%eax
je     1191 <order_dimms+0x71>
mov    %eax,%ebx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%r14d
add    %rdi,%r14
shl    $0x15,%edi
or     $0xfe00,%ebx
mov    $0xcfc,%esi
call   1040 <__builtin_outl@plt>
mov    $0xc260,%edi
mov    $0xcf8,%esi
call   1040 <__builtin_outl@plt>
mov    %rbx,%rdi
mov    $0xcfc,%esi
call   1040 <__builtin_outl@plt>
mov    $0x40,%edi
call   1030 <__builtin_inl@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1140 <order_dimms+0x20>
and    $0xffffff,%r14d
jmp    1194 <order_dimms+0x74>
xor    %r14d,%r14d
mov    %r14,%rdi
mov    $0x1234,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <__builtin_outl@plt>

LLVM IR (-O0):
define void @order_dimms() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i64 0, i64* %1
br label %6
6: ; preds = %19, %0
store i32 0, i32* %2
store i32 0, i32* %5
br label %7
7: ; preds = %12, %6
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call i32 @__builtin_inl(i32 64)
store i32 %11, i32* %2
br label %12
12: ; preds = %10
%13 = load i32, i32* %5
%14 = add i32 %13, 1
store i32 %14, i32* %5
br label %7
15: ; preds = %7
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
br label %38
19: ; preds = %15
%20 = load i32, i32* %2
store i32 %20, i32* %4
%21 = load i64, i64* %1
%22 = shl i64 %21, 21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %2
%24 = load i32, i32* %4
%25 = zext i32 %24 to i64
%26 = load i64, i64* %1
%27 = add i64 %26, %25
store i64 %27, i64* %1
%28 = load i32, i32* %4
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = or i32 %29, 65024
store i32 %30, i32* %3
%31 = load i32, i32* %2
%32 = zext i32 %31 to i64
%33 = call i32 @__builtin_outl(i64 %32, i32 3324)
%34 = call i32 @__builtin_outl(i64 49760, i32 3320)
%35 = load i32, i32* %3
%36 = zext i32 %35 to i64
%37 = call i32 @__builtin_outl(i64 %36, i32 3324)
br label %6
38: ; preds = %18
%39 = load i64, i64* %1
%40 = and i64 %39, 16777215
store i64 %40, i64* %1
%41 = load i64, i64* %1
%42 = call i32 @__builtin_outl(i64 %41, i32 4660)
ret void
}

LLVM IR (-O2):
define void @order_dimms() {
%1 = tail call i32 @__builtin_inl(i32 64)
%2 = icmp eq i32 %1, 0
br i1 %2, label %19, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %15, %3 ], [ %1, %0 ]
%5 = phi i64 [ %8, %3 ], [ 0, %0 ]
%6 = shl i64 %5, 21
%7 = zext i32 %4 to i64
%8 = add i64 %5, %7
%9 = or i32 %4, 65024
%10 = and i64 %6, 4292870144
%11 = tail call i32 @__builtin_outl(i64 %10, i32 3324)
%12 = tail call i32 @__builtin_outl(i64 49760, i32 3320)
%13 = zext i32 %9 to i64
%14 = tail call i32 @__builtin_outl(i64 %13, i32 3324)
%15 = tail call i32 @__builtin_inl(i32 64)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = and i64 %8, 16777215
br label %19
19: ; preds = %17, %0
%20 = phi i64 [ %18, %17 ], [ 0, %0 ]
%21 = tail call i32 @__builtin_outl(i64 %20, i32 4660)
ret void
}