#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 int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ printf(char *, int);
int samba_read(int, int, int);
int /*<<< orphan*/ serial_write(char *, int);
int /*<<< orphan*/ sys_delay(int);
int samba_connect(int board_rev) {
  char handshake[] = {0x80, 0x80, 0x23}, cmd[128], buffer[16384];
  int tstart, i, length, npages;
  int c;
  serial_write(handshake, 3);
  sys_delay(100);
  uint32_t id = samba_read(0xffffee40, 4, 10000000);
  printf("CPU ID: 0x%08x\n", id);
  if (board_rev == 2 && id != 0x019607A2)
    die("Not a 9263 CPU");
  if (board_rev == 3 && id != 0x819b05a2)
    die("Not a 9G45 CPU");
  return 0;
}


x86 assembly (clang, -O0):
<samba_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40b0,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe9b(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe93(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0x7(%rbp),%rdi
mov    $0x3,%esi
call   1070 <serial_write@plt>
mov    $0x64,%edi
call   1050 <sys_delay@plt>
mov    $0xffffee40,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
mov    %eax,-0x40a8(%rbp)
mov    -0x40a8(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jne    11dc <samba_connect+0x8c>
cmpl   $0x19607a2,-0x40a8(%rbp)
07 96 01
je     11dc <samba_connect+0x8c>
lea    0xe3c(%rip),%rdi
call   1060 <die@plt>
cmpl   $0x3,-0x4(%rbp)
jne    1202 <samba_connect+0xb2>
cmpl   $0x819b05a2,-0x40a8(%rbp)
05 9b 81
je     1202 <samba_connect+0xb2>
lea    0xe25(%rip),%rdi
call   1060 <die@plt>
xor    %eax,%eax
add    $0x40b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<samba_connect>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x23,0x6(%rsp)
movw   $0x8080,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x3,%esi
call   1070 <serial_write@plt>
mov    $0x64,%edi
call   1050 <sys_delay@plt>
mov    $0xffffee40,%edi
mov    $0x4,%esi
mov    $0x989680,%edx
call   1040 <samba_read@plt>
mov    %eax,%ebp
lea    0xe6c(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
cmp    $0x2,%ebx
jne    11b4 <samba_connect+0x64>
cmp    $0x19607a2,%ebp
je     11b4 <samba_connect+0x64>
lea    0xe61(%rip),%rdi
jmp    11c8 <samba_connect+0x78>
cmp    $0x3,%ebx
jne    11cd <samba_connect+0x7d>
cmp    $0x819b05a2,%ebp
je     11cd <samba_connect+0x7d>
lea    0xe5a(%rip),%rdi
call   1060 <die@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.samba_connect.handshake = [3 x i8] c"\80\80#"
@.str = [16 x i8] c"CPU ID: 0x%08x\0A\00"
@.str.1 = [15 x i8] c"Not a 9263 CPU\00"
@.str.2 = [15 x i8] c"Not a 9G45 CPU\00"
define i32 @samba_connect(i32 %0) {
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = alloca [128 x i8]
%5 = alloca [16384 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %2
%12 = bitcast [3 x i8]* %3 to i8*
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%14 = call i32 @serial_write(i8* %13, i32 3)
%15 = call i32 @sys_delay(i32 100)
%16 = call i32 @samba_read(i32 -4544, i32 4, i32 10000000)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %26
21: ; preds = %1
%22 = load i32, i32* %11
%23 = icmp ne i32 %22, 26609570
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21, %1
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, -2120546910
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %29, %26
ret i32 0
}

LLVM IR (-O2):
@__const.samba_connect.handshake = [3 x i8] c"\80\80#"
@.str = [16 x i8] c"CPU ID: 0x%08x\0A\00"
@.str.1 = [15 x i8] c"Not a 9263 CPU\00"
@.str.2 = [15 x i8] c"Not a 9G45 CPU\00"
define i32 @samba_connect(i32 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = call i32 @serial_write(i8* %3, i32 3)
%5 = call i32 @sys_delay(i32 100)
%6 = call i32 @samba_read(i32 -4544, i32 4, i32 10000000)
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %0, 2
%9 = icmp ne i32 %6, 26609570
%10 = and i1 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = icmp eq i32 %0, 3
%13 = icmp ne i32 %6, -2120546910
%14 = and i1 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11, %1
%16 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %11 ]
%17 = call i32 @die(i8* %16)
br label %18
18: ; preds = %15, %11
ret i32 0
}