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

/* Variables and functions */
int /*<<< orphan*/ iso_msgs_submit(int /*<<< orphan*/, char *,
                                   int /*<<< orphan*/, char *,
                                   int /*<<< orphan*/);
int insert_apm_head(uint8_t *buf, int apm_count) {
  int i;
  static uint8_t apm_mbr_start[32] = {
      0x33, 0xed, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
      0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
      0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
  static uint8_t apm_head[32] = {
      0x45, 0x52, 0x08, 0x00, 0x00, 0x00, 0x90, 0x90, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  if (apm_count) {
    for (i = 0; i < 32; i++)
      if (buf[i] != apm_mbr_start[i])
        break;
    if (i < 32) {
      for (i = 0; i < 32; i++)
        if (buf[i] != apm_head[i])
          break;
    }
    if (i < 32) {
      iso_msgs_submit(
          0, "MBR template file seems not prepared for Apple Partition Map.", 0,
          "FAILURE", 0);
      return 0xE030FEB9;
    }
    for (i = 0; i < 32; i++)
      buf[i] = apm_head[i];
  }
  return 1;
}


x86 assembly (clang, -O0):
<insert_apm_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1237 <insert_apm_head+0x127>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jge    1171 <insert_apm_head+0x61>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x18(%rbp),%rdx
lea    0x2ee0(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
je     115e <insert_apm_head+0x4e>
jmp    1171 <insert_apm_head+0x61>
jmp    1163 <insert_apm_head+0x53>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <insert_apm_head+0x20>
cmpl   $0x20,-0x18(%rbp)
jge    11c8 <insert_apm_head+0xb8>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jge    11c3 <insert_apm_head+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x18(%rbp),%rdx
lea    0x2f0e(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
je     11b0 <insert_apm_head+0xa0>
jmp    11c3 <insert_apm_head+0xb3>
jmp    11b5 <insert_apm_head+0xa5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <insert_apm_head+0x72>
jmp    11c8 <insert_apm_head+0xb8>
cmpl   $0x20,-0x18(%rbp)
jge    11fa <insert_apm_head+0xea>
xor    %r8d,%r8d
lea    0xe24(%rip),%rsi
lea    0xe5b(%rip),%rcx
mov    %r8d,%edi
mov    %r8d,%edx
call   1030 <iso_msgs_submit@plt>
movl   $0xe030feb9,-0x4(%rbp)
jmp    123e <insert_apm_head+0x12e>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jge    1232 <insert_apm_head+0x122>
movslq -0x18(%rbp),%rcx
lea    0x2e9a(%rip),%rax
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1201 <insert_apm_head+0xf1>
jmp    1237 <insert_apm_head+0x127>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_apm_head>:
push   %rax
mov    $0x1,%eax
test   %esi,%esi
je     121c <insert_apm_head+0x10c>
xor    %ecx,%ecx
lea    0xed9(%rip),%rdx
nopw   0x0(%rax,%rax,1)
mov    (%rdi,%rcx,4),%esi
cmp    (%rdx,%rcx,4),%esi
jne    1162 <insert_apm_head+0x52>
mov    0x4(%rdi,%rcx,4),%esi
cmp    0x4(%rdx,%rcx,4),%esi
jne    1162 <insert_apm_head+0x52>
mov    0x8(%rdi,%rcx,4),%esi
cmp    0x8(%rdx,%rcx,4),%esi
jne    1162 <insert_apm_head+0x52>
mov    0xc(%rdi,%rcx,4),%esi
cmp    0xc(%rdx,%rcx,4),%esi
jne    1162 <insert_apm_head+0x52>
add    $0x4,%rcx
cmp    $0x20,%rcx
jne    1130 <insert_apm_head+0x20>
jmp    11a4 <insert_apm_head+0x94>
xor    %ecx,%ecx
lea    0xf15(%rip),%rdx
nopl   0x0(%rax,%rax,1)
mov    (%rdi,%rcx,4),%esi
cmp    (%rdx,%rcx,4),%esi
jne    11fd <insert_apm_head+0xed>
mov    0x4(%rdi,%rcx,4),%esi
cmp    0x4(%rdx,%rcx,4),%esi
jne    11fd <insert_apm_head+0xed>
mov    0x8(%rdi,%rcx,4),%esi
cmp    0x8(%rdx,%rcx,4),%esi
jne    11fd <insert_apm_head+0xed>
mov    0xc(%rdi,%rcx,4),%esi
cmp    0xc(%rdx,%rcx,4),%esi
jne    11fd <insert_apm_head+0xed>
add    $0x4,%rcx
cmp    $0x20,%rcx
jne    1170 <insert_apm_head+0x60>
movaps 0xf45(%rip),%xmm0
movups %xmm0,0x70(%rdi)
movaps 0xf2a(%rip),%xmm0
movups %xmm0,0x60(%rdi)
movaps 0xf0f(%rip),%xmm0
movups %xmm0,0x50(%rdi)
movaps 0xef4(%rip),%xmm0
movups %xmm0,0x40(%rdi)
movaps 0xed9(%rip),%xmm0
movups %xmm0,0x30(%rdi)
movaps 0xebe(%rip),%xmm0
movups %xmm0,0x20(%rdi)
movaps 0xea3(%rip),%xmm0
movups %xmm0,0x10(%rdi)
movaps 0xe88(%rip),%xmm0
movups %xmm0,(%rdi)
pop    %rcx
ret
lea    0xefc(%rip),%rsi
lea    0xf33(%rip),%rcx
xor    %edi,%edi
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <iso_msgs_submit@plt>
mov    $0xe030feb9,%eax
pop    %rcx
ret

LLVM IR (-O0):
@insert_apm_head.apm_mbr_start = internal global [32 x i32] [i32 51, i32 237, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144]
@insert_apm_head.apm_head = internal global <{ [8 x i32], [24 x i32] }> <{ [8 x i32] [i32 69, i32 82, i32 8, i32 0, i32 0, i32 0, i32 144, i32 144], [24 x i32] zeroinitializer }>
@.str = [62 x i8] c"MBR template file seems not prepared for Apple Partition Map.\00"
@.str.1 = [8 x i8] c"FAILURE\00"
define i32 @insert_apm_head(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %75
9: ; preds = %2
store i32 0, i32* %6
br label %10
10: ; preds = %26, %9
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 32
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [32 x i32], [32 x i32]* @insert_apm_head.apm_mbr_start, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = icmp ne i32 %18, %22
br i1 %23, label %24, label %25
24: ; preds = %13
br label %29
25: ; preds = %13
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %10
29: ; preds = %24, %10
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 32
br i1 %31, label %32, label %53
32: ; preds = %29
store i32 0, i32* %6
br label %33
33: ; preds = %49, %32
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 32
br i1 %35, label %36, label %52
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp ne i32 %41, %45
br i1 %46, label %47, label %48
47: ; preds = %36
br label %52
48: ; preds = %36
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %33
52: ; preds = %47, %33
br label %53
53: ; preds = %52, %29
%54 = load i32, i32* %6
%55 = icmp slt i32 %54, 32
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 @iso_msgs_submit(i32 0, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 -533659975, i32* %3
br label %76
58: ; preds = %53
store i32 0, i32* %6
br label %59
59: ; preds = %71, %58
%60 = load i32, i32* %6
%61 = icmp slt i32 %60, 32
br i1 %61, label %62, label %74
62: ; preds = %59
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %64
%66 = load i32, i32* %65
%67 = load i32*, i32** %4
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
store i32 %66, i32* %70
br label %71
71: ; preds = %62
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %59
74: ; preds = %59
br label %75
75: ; preds = %74, %2
store i32 1, i32* %3
br label %76
76: ; preds = %75, %56
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@insert_apm_head.apm_mbr_start = internal unnamed_addr constant [32 x i32] [i32 51, i32 237, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144, i32 144]
@insert_apm_head.apm_head = internal unnamed_addr constant <{ [8 x i32], [24 x i32] }> <{ [8 x i32] [i32 69, i32 82, i32 8, i32 0, i32 0, i32 0, i32 144, i32 144], [24 x i32] zeroinitializer }>
@.str = [62 x i8] c"MBR template file seems not prepared for Apple Partition Map.\00"
@.str.1 = [8 x i8] c"FAILURE\00"
define i32 @insert_apm_head(i32* nocapture %0, i32 %1) {
%3 = bitcast i32* %0 to i8*
%4 = icmp eq i32 %1, 0
br i1 %4, label %71, label %29
5: ; preds = %29
%6 = or i64 %30, 1
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %7
%9 = getelementptr inbounds [32 x i32], [32 x i32]* @insert_apm_head.apm_mbr_start, i64 0, i64 %6
%10 = load i32, i32* %9
%11 = icmp eq i32 %8, %10
br i1 %11, label %12, label %36
12: ; preds = %5
%13 = or i64 %30, 2
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = getelementptr inbounds [32 x i32], [32 x i32]* @insert_apm_head.apm_mbr_start, i64 0, i64 %13
%17 = load i32, i32* %16
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %36
19: ; preds = %12
%20 = or i64 %30, 3
%21 = getelementptr inbounds i32, i32* %0, i64 %20
%22 = load i32, i32* %21
%23 = getelementptr inbounds [32 x i32], [32 x i32]* @insert_apm_head.apm_mbr_start, i64 0, i64 %20
%24 = load i32, i32* %23
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %36
26: ; preds = %19
%27 = add nuw nsw i64 %30, 4
%28 = icmp eq i64 %27, 32
br i1 %28, label %68, label %29
29: ; preds = %2, %26
%30 = phi i64 [ %27, %26 ], [ 0, %2 ]
%31 = getelementptr inbounds i32, i32* %0, i64 %30
%32 = load i32, i32* %31
%33 = getelementptr inbounds [32 x i32], [32 x i32]* @insert_apm_head.apm_mbr_start, i64 0, i64 %30
%34 = load i32, i32* %33
%35 = icmp eq i32 %32, %34
br i1 %35, label %5, label %36
36: ; preds = %19, %12, %5, %29
br label %61
37: ; preds = %61
%38 = or i64 %62, 1
%39 = getelementptr inbounds i32, i32* %0, i64 %38
%40 = load i32, i32* %39
%41 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %38
%42 = load i32, i32* %41
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %69
44: ; preds = %37
%45 = or i64 %62, 2
%46 = getelementptr inbounds i32, i32* %0, i64 %45
%47 = load i32, i32* %46
%48 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %45
%49 = load i32, i32* %48
%50 = icmp eq i32 %47, %49
br i1 %50, label %51, label %69
51: ; preds = %44
%52 = or i64 %62, 3
%53 = getelementptr inbounds i32, i32* %0, i64 %52
%54 = load i32, i32* %53
%55 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %52
%56 = load i32, i32* %55
%57 = icmp eq i32 %54, %56
br i1 %57, label %58, label %69
58: ; preds = %51
%59 = add nuw nsw i64 %62, 4
%60 = icmp eq i64 %59, 32
br i1 %60, label %68, label %61
61: ; preds = %58, %36
%62 = phi i64 [ 0, %36 ], [ %59, %58 ]
%63 = getelementptr inbounds i32, i32* %0, i64 %62
%64 = load i32, i32* %63
%65 = getelementptr inbounds [32 x i32], [32 x i32]* bitcast (<{ [8 x i32], [24 x i32] }>* @insert_apm_head.apm_head to [32 x i32]*), i64 0, i64 %62
%66 = load i32, i32* %65
%67 = icmp eq i32 %64, %66
br i1 %67, label %37, label %69
68: ; preds = %26, %58
br label %71
69: ; preds = %51, %44, %37, %61
%70 = tail call i32 @iso_msgs_submit(i32 0, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %71
71: ; preds = %68, %2, %69
%72 = phi i32 [ -533659975, %69 ], [ 1, %2 ], [ 1, %68 ]
ret i32 %72
}