#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*/ die(char *);
int /*<<< orphan*/ mbox_write(int, int, int);
int /*<<< orphan*/ samba_load_applet(char *, int);
int samba_read(int, int, int);
int /*<<< orphan*/ samba_run(int, int);
int ddr_init(int board_rev) {
  if (board_rev == 2)
    samba_load_applet("isp-extram-at91sam9263", 0x300000);
  else if (board_rev == 3)
    samba_load_applet("isp-extram-at91sam9g45", 0x300000);
  mbox_write(0x300000, 0x4, 0x00);
  mbox_write(0x300000, 0x10, 0);
  mbox_write(0x300000, 0x18, 1);
  mbox_write(0x300000, 0x14, 0);
  mbox_write(0x300000, 0x1c, 16);
  mbox_write(0x300000, 0x20, 0);
  samba_run(0x300000, 100000000);
  if ((samba_read(0x300000 + 0x4, 4, 10000000)) != ~0x00)
    die("invalid response from applet init");
  if ((samba_read(0x300000 + 0x8, 4, 10000000)) != 0x00)
    die("invalid response from applet status");
  return 0;
}


x86 assembly (clang, -O0):
<ddr_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    117b <ddr_init+0x2b>
lea    0xe94(%rip),%rdi
mov    $0x300000,%esi
call   1060 <samba_load_applet@plt>
jmp    119b <ddr_init+0x4b>
cmpl   $0x3,-0x4(%rbp)
jne    1196 <ddr_init+0x46>
lea    0xe8b(%rip),%rdi
mov    $0x300000,%esi
call   1060 <samba_load_applet@plt>
jmp    119b <ddr_init+0x4b>
mov    $0x300000,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x10,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x18,%esi
mov    $0x1,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x14,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x1c,%esi
mov    $0x10,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x5f5e100,%esi
call   1030 <samba_run@plt>
mov    $0x300004,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
cmp    $0xffffffff,%eax
je     123f <ddr_init+0xef>
lea    0xdf4(%rip),%rdi
call   1050 <die@plt>
mov    $0x300008,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
cmp    $0x0,%eax
je     1268 <ddr_init+0x118>
lea    0xded(%rip),%rdi
call   1050 <die@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddr_init>:
push   %rax
cmp    $0x2,%edi
je     1164 <ddr_init+0x14>
cmp    $0x3,%edi
jne    1175 <ddr_init+0x25>
lea    0xeb5(%rip),%rdi
jmp    116b <ddr_init+0x1b>
lea    0xe95(%rip),%rdi
mov    $0x300000,%esi
call   1060 <samba_load_applet@plt>
mov    $0x300000,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x10,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x18,%esi
mov    $0x1,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x14,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x1c,%esi
mov    $0x10,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x20,%esi
xor    %edx,%edx
call   1070 <mbox_write@plt>
mov    $0x300000,%edi
mov    $0x5f5e100,%esi
call   1030 <samba_run@plt>
mov    $0x300004,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
cmp    $0xffffffff,%eax
je     1215 <ddr_init+0xc5>
lea    0xe1e(%rip),%rdi
call   1050 <die@plt>
mov    $0x300008,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
test   %eax,%eax
je     1239 <ddr_init+0xe9>
lea    0xe1c(%rip),%rdi
call   1050 <die@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"isp-extram-at91sam9263\00"
@.str.1 = [23 x i8] c"isp-extram-at91sam9g45\00"
@.str.2 = [34 x i8] c"invalid response from applet init\00"
@.str.3 = [36 x i8] c"invalid response from applet status\00"
define i32 @ddr_init(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 2
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @samba_load_applet(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 3145728)
br label %13
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @samba_load_applet(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 3145728)
br label %12
12: ; preds = %10, %7
br label %13
13: ; preds = %12, %5
%14 = call i32 @mbox_write(i32 3145728, i32 4, i32 0)
%15 = call i32 @mbox_write(i32 3145728, i32 16, i32 0)
%16 = call i32 @mbox_write(i32 3145728, i32 24, i32 1)
%17 = call i32 @mbox_write(i32 3145728, i32 20, i32 0)
%18 = call i32 @mbox_write(i32 3145728, i32 28, i32 16)
%19 = call i32 @mbox_write(i32 3145728, i32 32, i32 0)
%20 = call i32 @samba_run(i32 3145728, i32 100000000)
%21 = call i32 @samba_read(i32 3145732, i32 4, i32 10000000)
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
%26 = call i32 @samba_read(i32 3145736, i32 4, i32 10000000)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"isp-extram-at91sam9263\00"
@.str.1 = [23 x i8] c"isp-extram-at91sam9g45\00"
@.str.2 = [34 x i8] c"invalid response from applet init\00"
@.str.3 = [36 x i8] c"invalid response from applet status\00"
define i32 @ddr_init(i32 %0) {
switch i32 %0, label %6 [
i32 2, label %3
i32 3, label %2
]
2: ; preds = %1
br label %3
3: ; preds = %1, %2
%4 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %1 ]
%5 = tail call i32 @samba_load_applet(i8* %4, i32 3145728)
br label %6
6: ; preds = %3, %1
%7 = tail call i32 @mbox_write(i32 3145728, i32 4, i32 0)
%8 = tail call i32 @mbox_write(i32 3145728, i32 16, i32 0)
%9 = tail call i32 @mbox_write(i32 3145728, i32 24, i32 1)
%10 = tail call i32 @mbox_write(i32 3145728, i32 20, i32 0)
%11 = tail call i32 @mbox_write(i32 3145728, i32 28, i32 16)
%12 = tail call i32 @mbox_write(i32 3145728, i32 32, i32 0)
%13 = tail call i32 @samba_run(i32 3145728, i32 100000000)
%14 = tail call i32 @samba_read(i32 3145732, i32 4, i32 10000000)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %6
%17 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %6
%19 = tail call i32 @samba_read(i32 3145736, i32 4, i32 10000000)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret i32 0
}