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

/* Variables and functions */
void build_partition(uint8_t *buf, int boot, int type, uint32_t start_block,
                     uint32_t num_blocks) {
  buf[0] = boot;
  if (num_blocks == 0) {
    buf[1] = 0;
    buf[2] = 0;
    buf[3] = 0;
  } else {
    buf[1] = 0xff;
    buf[2] = 0xff;
    buf[3] = 0xff;
  }
  buf[4] = type;
  if (num_blocks == 0) {
    buf[5] = 0;
    buf[6] = 0;
    buf[7] = 0;
  } else {
    buf[5] = 0xff;
    buf[6] = 0xff;
    buf[7] = 0xff;
  }
  buf[8] = start_block;
  buf[9] = start_block >> 8;
  buf[10] = start_block >> 16;
  buf[11] = start_block >> 24;
  buf[12] = num_blocks;
  buf[13] = num_blocks >> 8;
  buf[14] = num_blocks >> 16;
  buf[15] = num_blocks >> 24;
}


x86 assembly (clang, -O0):
<build_partition>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x18(%rbp)
jne    114e <build_partition+0x4e>
mov    -0x8(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0xc(%rax)
jmp    116f <build_partition+0x6f>
mov    -0x8(%rbp),%rax
movl   $0xff,0x4(%rax)
mov    -0x8(%rbp),%rax
movl   $0xff,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0xff,0xc(%rax)
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
cmpl   $0x0,-0x18(%rbp)
jne    11a9 <build_partition+0xa9>
mov    -0x8(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x18(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x1c(%rax)
jmp    11ca <build_partition+0xca>
mov    -0x8(%rbp),%rax
movl   $0xff,0x14(%rax)
mov    -0x8(%rbp),%rax
movl   $0xff,0x18(%rax)
mov    -0x8(%rbp),%rax
movl   $0xff,0x1c(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x24(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x2c(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x18(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x34(%rax)
mov    -0x18(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x38(%rax)
mov    -0x18(%rbp),%ecx
sar    $0x18,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x3c(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_partition>:
mov    %esi,(%rdi)
test   %r8d,%r8d
mov    $0xff,%eax
cmove  %r8d,%eax
mov    %eax,0x4(%rdi)
mov    %eax,0x8(%rdi)
mov    %eax,0xc(%rdi)
mov    %edx,0x10(%rdi)
mov    %eax,0x14(%rdi)
mov    %eax,0x18(%rdi)
mov    %eax,0x1c(%rdi)
mov    %ecx,0x20(%rdi)
mov    %ecx,%eax
sar    $0x8,%eax
mov    %eax,0x24(%rdi)
mov    %ecx,%eax
sar    $0x10,%eax
mov    %eax,0x28(%rdi)
sar    $0x18,%ecx
mov    %ecx,0x2c(%rdi)
mov    %r8d,0x30(%rdi)
mov    %r8d,%eax
sar    $0x8,%eax
mov    %eax,0x34(%rdi)
mov    %r8d,%eax
sar    $0x10,%eax
mov    %eax,0x38(%rdi)
sar    $0x18,%r8d
mov    %r8d,0x3c(%rdi)
ret

LLVM IR (-O0):
define void @build_partition(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load i32, i32* %7
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 0
store i32 %11, i32* %13
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %5
%17 = load i32*, i32** %6
%18 = getelementptr inbounds i32, i32* %17, i64 1
store i32 0, i32* %18
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i64 2
store i32 0, i32* %20
%21 = load i32*, i32** %6
%22 = getelementptr inbounds i32, i32* %21, i64 3
store i32 0, i32* %22
br label %30
23: ; preds = %5
%24 = load i32*, i32** %6
%25 = getelementptr inbounds i32, i32* %24, i64 1
store i32 255, i32* %25
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 2
store i32 255, i32* %27
%28 = load i32*, i32** %6
%29 = getelementptr inbounds i32, i32* %28, i64 3
store i32 255, i32* %29
br label %30
30: ; preds = %23, %16
%31 = load i32, i32* %8
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 4
store i32 %31, i32* %33
%34 = load i32, i32* %10
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %30
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i64 5
store i32 0, i32* %38
%39 = load i32*, i32** %6
%40 = getelementptr inbounds i32, i32* %39, i64 6
store i32 0, i32* %40
%41 = load i32*, i32** %6
%42 = getelementptr inbounds i32, i32* %41, i64 7
store i32 0, i32* %42
br label %50
43: ; preds = %30
%44 = load i32*, i32** %6
%45 = getelementptr inbounds i32, i32* %44, i64 5
store i32 255, i32* %45
%46 = load i32*, i32** %6
%47 = getelementptr inbounds i32, i32* %46, i64 6
store i32 255, i32* %47
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 7
store i32 255, i32* %49
br label %50
50: ; preds = %43, %36
%51 = load i32, i32* %9
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 8
store i32 %51, i32* %53
%54 = load i32, i32* %9
%55 = ashr i32 %54, 8
%56 = load i32*, i32** %6
%57 = getelementptr inbounds i32, i32* %56, i64 9
store i32 %55, i32* %57
%58 = load i32, i32* %9
%59 = ashr i32 %58, 16
%60 = load i32*, i32** %6
%61 = getelementptr inbounds i32, i32* %60, i64 10
store i32 %59, i32* %61
%62 = load i32, i32* %9
%63 = ashr i32 %62, 24
%64 = load i32*, i32** %6
%65 = getelementptr inbounds i32, i32* %64, i64 11
store i32 %63, i32* %65
%66 = load i32, i32* %10
%67 = load i32*, i32** %6
%68 = getelementptr inbounds i32, i32* %67, i64 12
store i32 %66, i32* %68
%69 = load i32, i32* %10
%70 = ashr i32 %69, 8
%71 = load i32*, i32** %6
%72 = getelementptr inbounds i32, i32* %71, i64 13
store i32 %70, i32* %72
%73 = load i32, i32* %10
%74 = ashr i32 %73, 16
%75 = load i32*, i32** %6
%76 = getelementptr inbounds i32, i32* %75, i64 14
store i32 %74, i32* %76
%77 = load i32, i32* %10
%78 = ashr i32 %77, 24
%79 = load i32*, i32** %6
%80 = getelementptr inbounds i32, i32* %79, i64 15
store i32 %78, i32* %80
ret void
}

LLVM IR (-O2):
define void @build_partition(i32* writeonly %0, i32 %1, i32 %2, i32 %3, i32 %4) {
store i32 %1, i32* %0
%6 = icmp eq i32 %4, 0
%7 = select i1 %6, i32 0, i32 255
%8 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %7, i32* %8
%9 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %7, i32* %9
%10 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %7, i32* %10
%11 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %2, i32* %11
%12 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %7, i32* %12
%13 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %7, i32* %13
%14 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %7, i32* %14
%15 = getelementptr inbounds i32, i32* %0, i64 8
store i32 %3, i32* %15
%16 = ashr i32 %3, 8
%17 = getelementptr inbounds i32, i32* %0, i64 9
store i32 %16, i32* %17
%18 = ashr i32 %3, 16
%19 = getelementptr inbounds i32, i32* %0, i64 10
store i32 %18, i32* %19
%20 = ashr i32 %3, 24
%21 = getelementptr inbounds i32, i32* %0, i64 11
store i32 %20, i32* %21
%22 = getelementptr inbounds i32, i32* %0, i64 12
store i32 %4, i32* %22
%23 = ashr i32 %4, 8
%24 = getelementptr inbounds i32, i32* %0, i64 13
store i32 %23, i32* %24
%25 = ashr i32 %4, 16
%26 = getelementptr inbounds i32, i32* %0, i64 14
store i32 %25, i32* %26
%27 = ashr i32 %4, 24
%28 = getelementptr inbounds i32, i32* %0, i64 15
store i32 %27, i32* %28
ret void
}