#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*/ strncpy(char *, char *, int);
int /*<<< orphan*/ udelay20();
void ethmac_tx_packet(char *buf, int len) {
  unsigned int status = 0;
  strncpy((char *)0x03040002, buf, len);
  status = *(volatile unsigned int *)(0x20000400 + 0);
  while ((status & 0x8000) != 0) {
    udelay20();
    status = *(volatile unsigned int *)(0x20000400 + 0);
  }
  *(unsigned int *)(0x20000400 + 0) = len << 16 | 0xf800;
}


x86 assembly (clang, -O0):
<ethmac_tx_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x3040002,%edi
call   1030 <strncpy@plt>
mov    $0x20000400,%eax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     1178 <ethmac_tx_packet+0x58>
mov    $0x0,%al
call   1040 <udelay20@plt>
mov    $0x20000400,%eax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    1151 <ethmac_tx_packet+0x31>
mov    -0xc(%rbp),%ecx
shl    $0x10,%ecx
or     $0xf800,%ecx
mov    $0x20000400,%eax
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ethmac_tx_packet>:
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rsi
mov    $0x3040002,%edi
mov    %ebx,%edx
call   1030 <strncpy@plt>
testl  $0x8000,0x20000400
je     1154 <ethmac_tx_packet+0x34>
nop
xor    %eax,%eax
call   1040 <udelay20@plt>
testl  $0x8000,0x20000400
jne    1140 <ethmac_tx_packet+0x20>
shl    $0x10,%ebx
or     $0xf800,%ebx
mov    %ebx,0x20000400
pop    %rbx
ret

LLVM IR (-O0):
define void @ethmac_tx_packet(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = call i32 @strncpy(i8* inttoptr (i64 50593794 to i8*), i8* %6, i32 %7)
%9 = load volatile i32, i32* inttoptr (i64 536871936 to i32*)
store i32 %9, i32* %5
br label %10
10: ; preds = %14, %2
%11 = load i32, i32* %5
%12 = and i32 %11, 32768
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 (...) @udelay20()
%16 = load volatile i32, i32* inttoptr (i64 536871936 to i32*)
store i32 %16, i32* %5
br label %10
17: ; preds = %10
%18 = load i32, i32* %4
%19 = shl i32 %18, 16
%20 = or i32 %19, 63488
store i32 %20, i32* inttoptr (i64 536871936 to i32*)
ret void
}

LLVM IR (-O2):
define void @ethmac_tx_packet(i8* %0, i32 %1) {
%3 = tail call i32 @strncpy(i8* inttoptr (i64 50593794 to i8*), i8* %0, i32 %1)
%4 = load volatile i32, i32* inttoptr (i64 536871936 to i32*)
%5 = and i32 %4, 32768
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2, %7
%8 = tail call i32 (...) @udelay20()
%9 = load volatile i32, i32* inttoptr (i64 536871936 to i32*)
%10 = and i32 %9, 32768
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7, %2
%13 = shl i32 %1, 16
%14 = or i32 %13, 63488
store i32 %14, i32* inttoptr (i64 536871936 to i32*)
ret void
}