#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 read_wordL(int);
int /*<<< orphan*/ write_word(int, int);
void cs_init(unsigned char *my_MAC_addr) {
  unsigned int nReturn = 0;
  write_word(0x000A, 0x0114);
  write_word(0x000C, 0x0040);
  while (!(nReturn & 0x0080)) {
    write_word(0x000A, 0x0136);
    nReturn = read_wordL(0x000C);
  }
  write_word(0x000A, 0x0104);
  write_word(0x000C, 0x0100 | 0x0400 | 0x0800);
  nReturn = read_wordL(0x000C);
  write_word(0x000A, 0x0158);
  write_word(0x000C, (my_MAC_addr[1] << 8) | my_MAC_addr[0]);
  write_word(0x000A, 0x0158 + 2);
  write_word(0x000C, (my_MAC_addr[3] << 8) | my_MAC_addr[2]);
  write_word(0x000A, 0x0158 + 4);
  write_word(0x000C, (my_MAC_addr[5] << 8) | my_MAC_addr[4]);
  write_word(0x000A, 0x0112);
  write_word(0x000C, 0x0040 | 0x0080);
}


x86 assembly (clang, -O0):
<cs_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0xa,%edi
mov    $0x114,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0x40,%esi
call   1040 <write_word@plt>
mov    -0xc(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116e <cs_init+0x4e>
jmp    118f <cs_init+0x6f>
mov    $0xa,%edi
mov    $0x136,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
call   1030 <read_wordL@plt>
mov    %eax,-0xc(%rbp)
jmp    1151 <cs_init+0x31>
mov    $0xa,%edi
mov    $0x104,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0xd00,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
call   1030 <read_wordL@plt>
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
mov    $0x158,%esi
call   1040 <write_word@plt>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%esi
shl    $0x8,%esi
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
or     %eax,%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x15a,%esi
call   1040 <write_word@plt>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%esi
shl    $0x8,%esi
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
or     %eax,%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x15c,%esi
call   1040 <write_word@plt>
mov    -0x8(%rbp),%rax
movzbl 0x5(%rax),%esi
shl    $0x8,%esi
mov    -0x8(%rbp),%rax
movzbl 0x4(%rax),%eax
or     %eax,%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x112,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0xc0,%esi
call   1040 <write_word@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cs_init>:
push   %rbx
mov    %rdi,%rbx
mov    $0xa,%edi
mov    $0x114,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0x40,%esi
call   1040 <write_word@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
mov    $0x136,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
call   1030 <read_wordL@plt>
test   $0x80,%al
je     1150 <cs_init+0x30>
mov    $0xa,%edi
mov    $0x104,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0xd00,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
call   1030 <read_wordL@plt>
mov    $0xa,%edi
mov    $0x158,%esi
call   1040 <write_word@plt>
movzwl (%rbx),%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x15a,%esi
call   1040 <write_word@plt>
movzwl 0x2(%rbx),%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x15c,%esi
call   1040 <write_word@plt>
movzwl 0x4(%rbx),%esi
mov    $0xc,%edi
call   1040 <write_word@plt>
mov    $0xa,%edi
mov    $0x112,%esi
call   1040 <write_word@plt>
mov    $0xc,%edi
mov    $0xc0,%esi
pop    %rbx
jmp    1040 <write_word@plt>

LLVM IR (-O0):
define void @cs_init(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = call i32 @write_word(i32 10, i32 276)
%5 = call i32 @write_word(i32 12, i32 64)
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %3
%8 = and i32 %7, 128
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call i32 @write_word(i32 10, i32 310)
%13 = call i32 @read_wordL(i32 12)
store i32 %13, i32* %3
br label %6
14: ; preds = %6
%15 = call i32 @write_word(i32 10, i32 260)
%16 = call i32 @write_word(i32 12, i32 3328)
%17 = call i32 @read_wordL(i32 12)
store i32 %17, i32* %3
%18 = call i32 @write_word(i32 10, i32 344)
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 8
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %23, %27
%29 = call i32 @write_word(i32 12, i32 %28)
%30 = call i32 @write_word(i32 10, i32 346)
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 3
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = shl i32 %34, 8
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = or i32 %35, %39
%41 = call i32 @write_word(i32 12, i32 %40)
%42 = call i32 @write_word(i32 10, i32 348)
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 5
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = shl i32 %46, 8
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 4
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = or i32 %47, %51
%53 = call i32 @write_word(i32 12, i32 %52)
%54 = call i32 @write_word(i32 10, i32 274)
%55 = call i32 @write_word(i32 12, i32 192)
ret void
}

LLVM IR (-O2):
define void @cs_init(i8* nocapture %0) {
%2 = tail call i32 @write_word(i32 10, i32 276)
%3 = tail call i32 @write_word(i32 12, i32 64)
br label %4
4: ; preds = %1, %4
%5 = tail call i32 @write_word(i32 10, i32 310)
%6 = tail call i32 @read_wordL(i32 12)
%7 = and i32 %6, 128
%8 = icmp eq i32 %7, 0
br i1 %8, label %4, label %9
9: ; preds = %4
%10 = tail call i32 @write_word(i32 10, i32 260)
%11 = tail call i32 @write_word(i32 12, i32 3328)
%12 = tail call i32 @read_wordL(i32 12)
%13 = tail call i32 @write_word(i32 10, i32 344)
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = load i8, i8* %0
%19 = zext i8 %18 to i32
%20 = or i32 %17, %19
%21 = tail call i32 @write_word(i32 12, i32 %20)
%22 = tail call i32 @write_word(i32 10, i32 346)
%23 = getelementptr inbounds i8, i8* %0, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl nuw nsw i32 %25, 8
%27 = getelementptr inbounds i8, i8* %0, i64 2
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = or i32 %26, %29
%31 = tail call i32 @write_word(i32 12, i32 %30)
%32 = tail call i32 @write_word(i32 10, i32 348)
%33 = getelementptr inbounds i8, i8* %0, i64 5
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = shl nuw nsw i32 %35, 8
%37 = getelementptr inbounds i8, i8* %0, i64 4
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = or i32 %36, %39
%41 = tail call i32 @write_word(i32 12, i32 %40)
%42 = tail call i32 @write_word(i32 10, i32 274)
%43 = tail call i32 @write_word(i32 12, i32 192)
ret void
}