#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 /*<<< orphan*/ pbFirmware;

/* Variables and functions */
int /*<<< orphan*/ McDevIf_AddPacket(int, unsigned char);
int /*<<< orphan*/ McDevIf_AddPacketRepeat(int, unsigned char const *,
                                           unsigned long);
int /*<<< orphan*/ McDevIf_ExecutePacket();
int /*<<< orphan*/ McDevIf_ReadDirect(int, unsigned char *);
void DownloadOS(const unsigned char *pbFirmware) {
  unsigned char bData;
  unsigned char abMsel;
  unsigned char abAdrH;
  unsigned char abAdrL;
  unsigned short awOsSize;
  const unsigned char *apbOsProg;
  abMsel = (unsigned char)(0x40);
  abAdrL = pbFirmware[0];
  abAdrH = pbFirmware[1];
  awOsSize = ((unsigned short)((unsigned long)(pbFirmware[2]) & 0xff) |
              (unsigned short)(((unsigned long)(pbFirmware[3]) & 0xff) << 8));
  apbOsProg = &pbFirmware[4];
  McDevIf_ReadDirect(((0x00004000UL) | (unsigned long)(110)), &bData);
  bData &= (unsigned char)~(0x10);
  bData |= (0x01);
  McDevIf_AddPacket(((0x20000000UL) | (0x00004000UL) | (unsigned long)(110)),
                    bData);
  bData &= (unsigned char)~(0xC0);
  bData |= abMsel;
  McDevIf_AddPacket(((0x20000000UL) | (0x00004000UL) | (unsigned long)(110)),
                    bData);
  McDevIf_AddPacket(((0x20000000UL) | (0x00004000UL) | (unsigned long)(114)),
                    abAdrH);
  McDevIf_AddPacket(((0x20000000UL) | (0x00004000UL) | (unsigned long)(115)),
                    abAdrL);
  McDevIf_ExecutePacket();
  McDevIf_AddPacketRepeat(
      ((0x20000000UL) | (0x00000000UL) | (unsigned long)(29)), apbOsProg,
      ((unsigned long)awOsSize * 2UL));
  McDevIf_ExecutePacket();
}


x86 assembly (clang, -O0):
<DownloadOS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x40,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xff,%rax
movzwl %ax,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
and    $0xff,%rcx
shl    $0x8,%rcx
movzwl %cx,%ecx
or     %ecx,%eax
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    $0x406e,%edi
lea    -0x9(%rbp),%rsi
call   1030 <McDevIf_ReadDirect@plt>
movzbl -0x9(%rbp),%eax
and    $0xef,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x9(%rbp)
mov    $0x2000406e,%edi
movzbl -0x9(%rbp),%esi
call   1050 <McDevIf_AddPacket@plt>
movzbl -0x9(%rbp),%eax
and    $0x3f,%eax
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%ecx
movzbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
mov    $0x2000406e,%edi
movzbl -0x9(%rbp),%esi
call   1050 <McDevIf_AddPacket@plt>
mov    $0x20004072,%edi
movzbl -0xb(%rbp),%esi
call   1050 <McDevIf_AddPacket@plt>
mov    $0x20004073,%edi
movzbl -0xc(%rbp),%esi
call   1050 <McDevIf_AddPacket@plt>
mov    $0x0,%al
call   1040 <McDevIf_ExecutePacket@plt>
mov    -0x18(%rbp),%rsi
movzwl -0xe(%rbp),%eax
mov    %eax,%edx
shl    $0x1,%rdx
mov    $0x2000001d,%edi
call   1060 <McDevIf_AddPacketRepeat@plt>
mov    $0x0,%al
call   1040 <McDevIf_ExecutePacket@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DownloadOS>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movzbl (%rdi),%r12d
movzbl 0x1(%rdi),%ebx
movzbl 0x2(%rdi),%r15d
movzbl 0x3(%rdi),%ebp
lea    0x4(%rdi),%r14
lea    0xf(%rsp),%rsi
mov    $0x406e,%edi
call   1030 <McDevIf_ReadDirect@plt>
mov    0xf(%rsp),%al
and    $0xee,%al
or     $0x1,%al
mov    %al,0xf(%rsp)
movzbl %al,%esi
mov    $0x2000406e,%edi
call   1050 <McDevIf_AddPacket@plt>
mov    0xf(%rsp),%al
and    $0x3f,%al
or     $0x40,%al
mov    %al,0xf(%rsp)
movzbl %al,%esi
mov    $0x2000406e,%edi
call   1050 <McDevIf_AddPacket@plt>
mov    $0x20004072,%edi
mov    %ebx,%esi
call   1050 <McDevIf_AddPacket@plt>
mov    $0x20004073,%edi
mov    %r12d,%esi
call   1050 <McDevIf_AddPacket@plt>
xor    %eax,%eax
call   1040 <McDevIf_ExecutePacket@plt>
shl    $0x9,%rbp
lea    0x0(,%r15,2),%rdx
add    %rbp,%rdx
mov    $0x2000001d,%edi
mov    %r14,%rsi
call   1060 <McDevIf_AddPacketRepeat@plt>
xor    %eax,%eax
call   1040 <McDevIf_ExecutePacket@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @DownloadOS(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i16
%8 = alloca i8*
store i8* %0, i8** %2
store i8 64, i8* %4
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
store i8 %11, i8* %6
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
store i8 %14, i8* %5
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8, i8* %16
%18 = zext i8 %17 to i64
%19 = and i64 %18, 255
%20 = trunc i64 %19 to i16
%21 = zext i16 %20 to i32
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i64
%26 = and i64 %25, 255
%27 = shl i64 %26, 8
%28 = trunc i64 %27 to i16
%29 = zext i16 %28 to i32
%30 = or i32 %21, %29
%31 = trunc i32 %30 to i16
store i16 %31, i16* %7
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %8
%34 = call i32 @McDevIf_ReadDirect(i32 16494, i8* %3)
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = and i32 %36, 239
%38 = trunc i32 %37 to i8
store i8 %38, i8* %3
%39 = load i8, i8* %3
%40 = zext i8 %39 to i32
%41 = or i32 %40, 1
%42 = trunc i32 %41 to i8
store i8 %42, i8* %3
%43 = load i8, i8* %3
%44 = call i32 @McDevIf_AddPacket(i32 536887406, i8 zeroext %43)
%45 = load i8, i8* %3
%46 = zext i8 %45 to i32
%47 = and i32 %46, 63
%48 = trunc i32 %47 to i8
store i8 %48, i8* %3
%49 = load i8, i8* %4
%50 = zext i8 %49 to i32
%51 = load i8, i8* %3
%52 = zext i8 %51 to i32
%53 = or i32 %52, %50
%54 = trunc i32 %53 to i8
store i8 %54, i8* %3
%55 = load i8, i8* %3
%56 = call i32 @McDevIf_AddPacket(i32 536887406, i8 zeroext %55)
%57 = load i8, i8* %5
%58 = call i32 @McDevIf_AddPacket(i32 536887410, i8 zeroext %57)
%59 = load i8, i8* %6
%60 = call i32 @McDevIf_AddPacket(i32 536887411, i8 zeroext %59)
%61 = call i32 (...) @McDevIf_ExecutePacket()
%62 = load i8*, i8** %8
%63 = load i16, i16* %7
%64 = zext i16 %63 to i64
%65 = mul i64 %64, 2
%66 = call i32 @McDevIf_AddPacketRepeat(i32 536870941, i8* %62, i64 %65)
%67 = call i32 (...) @McDevIf_ExecutePacket()
ret void
}

LLVM IR (-O2):
define void @DownloadOS(i8* %0) {
%2 = alloca i8
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = zext i8 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 3
%10 = load i8, i8* %9
%11 = zext i8 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 4
%13 = call i32 @McDevIf_ReadDirect(i32 16494, i8* %2)
%14 = load i8, i8* %2
%15 = and i8 %14, -18
%16 = or i8 %15, 1
store i8 %16, i8* %2
%17 = call i32 @McDevIf_AddPacket(i32 536887406, i8 zeroext %16)
%18 = load i8, i8* %2
%19 = and i8 %18, 63
%20 = or i8 %19, 64
store i8 %20, i8* %2
%21 = call i32 @McDevIf_AddPacket(i32 536887406, i8 zeroext %20)
%22 = call i32 @McDevIf_AddPacket(i32 536887410, i8 zeroext %5)
%23 = call i32 @McDevIf_AddPacket(i32 536887411, i8 zeroext %3)
%24 = call i32 (...) @McDevIf_ExecutePacket()
%25 = shl nuw nsw i64 %11, 9
%26 = shl nuw nsw i64 %8, 1
%27 = or i64 %25, %26
%28 = call i32 @McDevIf_AddPacketRepeat(i32 536870941, i8* %12, i64 %27)
%29 = call i32 (...) @McDevIf_ExecutePacket()
ret void
}