#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*/ serial_put_dec(unsigned int);
int /*<<< orphan*/ serial_puts(char *);
void print_ddr_size(unsigned int size) {
  serial_puts("DDR size: ");
  unsigned int mem_size = size >> 20;
  (mem_size) >= 1024 ? serial_put_dec(mem_size >> 10)
                     : serial_put_dec(mem_size);
  (mem_size) >= 1024 ? serial_puts("GB") : serial_puts("MB");
  serial_puts("\n");
}


x86 assembly (clang, -O0):
<print_ddr_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rdi
call   1030 <serial_puts@plt>
mov    -0x4(%rbp),%eax
shr    $0x14,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jb     115d <print_ddr_size+0x3d>
mov    -0x8(%rbp),%edi
shr    $0xa,%edi
call   1040 <serial_put_dec@plt>
jmp    1165 <print_ddr_size+0x45>
mov    -0x8(%rbp),%edi
call   1040 <serial_put_dec@plt>
cmpl   $0x400,-0x8(%rbp)
jb     1183 <print_ddr_size+0x63>
lea    0xe92(%rip),%rdi
call   1030 <serial_puts@plt>
jmp    118f <print_ddr_size+0x6f>
lea    0xe84(%rip),%rdi
call   1030 <serial_puts@plt>
lea    0xe7b(%rip),%rdi
call   1030 <serial_puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ddr_size>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xed3(%rip),%rdi
call   1030 <serial_puts@plt>
cmp    $0x40000000,%ebx
lea    0xecc(%rip),%rax
lea    0xec8(%rip),%r14
cmovae %rax,%r14
mov    $0x1e,%eax
mov    $0x14,%ecx
cmovae %eax,%ecx
shr    %cl,%ebx
mov    %ebx,%edi
call   1040 <serial_put_dec@plt>
mov    %r14,%rdi
call   1030 <serial_puts@plt>
lea    0xea2(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <serial_puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"DDR size: \00"
@.str.1 = [3 x i8] c"GB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_ddr_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @serial_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
%6 = lshr i32 %5, 20
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp uge i32 %7, 1024
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* %3
%11 = lshr i32 %10, 10
%12 = call i32 @serial_put_dec(i32 %11)
br label %16
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i32 @serial_put_dec(i32 %14)
br label %16
16: ; preds = %13, %9
%17 = phi i32 [ %12, %9 ], [ %15, %13 ]
%18 = load i32, i32* %3
%19 = icmp uge i32 %18, 1024
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @serial_puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 @serial_puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = phi i32 [ %21, %20 ], [ %23, %22 ]
%26 = call i32 @serial_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"DDR size: \00"
@.str.1 = [3 x i8] c"GB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_ddr_size(i32 %0) {
%2 = tail call i32 @serial_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp ugt i32 %0, 1073741823
%4 = select i1 %3, i32 30, i32 20
%5 = select i1 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%6 = lshr i32 %0, %4
%7 = tail call i32 @serial_put_dec(i32 %6)
%8 = tail call i32 @serial_puts(i8* %5)
%9 = tail call i32 @serial_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}