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

/* Variables and functions */
int apic_get_maxlvt(int /*<<< orphan*/ *);
scalar_t__ apic_is_integrated(int /*<<< orphan*/ *);
void apic_clear(uint8_t *baseapic) {
  uint32_t maxlvt = apic_get_maxlvt(baseapic);
  *((uint32_t *)&baseapic[0x380]) = 0;
  if (maxlvt >= 3) {
    *((uint32_t *)&baseapic[0x370]) |= (1 << 16);
  }
  *((uint32_t *)&baseapic[0x320]) |= (1 << 16);
  *((uint32_t *)&baseapic[0x350]) |= (1 << 16);
  *((uint32_t *)&baseapic[0x360]) |= (1 << 16);
  if (maxlvt >= 4) {
    *((uint32_t *)&baseapic[0x340]) |= (1 << 16);
  }
  if (maxlvt >= 6) {
    *((uint32_t *)&baseapic[0x2f0]) |= (1 << 16);
  }
  *((uint32_t *)&baseapic[0x320]) = (1 << 16);
  *((uint32_t *)&baseapic[0x350]) = (1 << 16);
  *((uint32_t *)&baseapic[0x360]) = (1 << 16);
  if (maxlvt >= 3) {
    *((uint32_t *)&baseapic[0x370]) = (1 << 16);
  }
  if (maxlvt >= 4) {
    *((uint32_t *)&baseapic[0x340]) = (1 << 16);
  }
  if (maxlvt >= 6) {
    *((uint32_t *)&baseapic[0x2f0]) = (1 << 16);
  }
  if (apic_is_integrated(baseapic)) {
    uint32_t fake __attribute__((unused));
    if (maxlvt > 3) {
      *((uint32_t *)&baseapic[0x280]) = 0;
    }
    fake = *((uint32_t *)&baseapic[0x280]);
  }
}


x86 assembly (clang, -O0):
<apic_clear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <apic_get_maxlvt@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,0xe00(%rax)
cmpl   $0x3,-0xc(%rbp)
jl     1166 <apic_clear+0x46>
mov    -0x8(%rbp),%rax
mov    0xdc0(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xdc0(%rax)
mov    -0x8(%rbp),%rax
mov    0xc80(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xc80(%rax)
mov    -0x8(%rbp),%rax
mov    0xd40(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xd40(%rax)
mov    -0x8(%rbp),%rax
mov    0xd80(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xd80(%rax)
cmpl   $0x4,-0xc(%rbp)
jl     11c8 <apic_clear+0xa8>
mov    -0x8(%rbp),%rax
mov    0xd00(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xd00(%rax)
cmpl   $0x6,-0xc(%rbp)
jl     11e8 <apic_clear+0xc8>
mov    -0x8(%rbp),%rax
mov    0xbc0(%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,0xbc0(%rax)
mov    -0x8(%rbp),%rax
movl   $0x10000,0xc80(%rax)
mov    -0x8(%rbp),%rax
movl   $0x10000,0xd40(%rax)
mov    -0x8(%rbp),%rax
movl   $0x10000,0xd80(%rax)
cmpl   $0x3,-0xc(%rbp)
jl     122a <apic_clear+0x10a>
mov    -0x8(%rbp),%rax
movl   $0x10000,0xdc0(%rax)
cmpl   $0x4,-0xc(%rbp)
jl     1242 <apic_clear+0x122>
mov    -0x8(%rbp),%rax
movl   $0x10000,0xd00(%rax)
cmpl   $0x6,-0xc(%rbp)
jl     125a <apic_clear+0x13a>
mov    -0x8(%rbp),%rax
movl   $0x10000,0xbc0(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <apic_is_integrated@plt>
cmp    $0x0,%rax
je     1292 <apic_clear+0x172>
cmpl   $0x3,-0xc(%rbp)
jle    1285 <apic_clear+0x165>
mov    -0x8(%rbp),%rax
movl   $0x0,0xa00(%rax)
mov    -0x8(%rbp),%rax
mov    0xa00(%rax),%eax
mov    %eax,-0x10(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apic_clear>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <apic_get_maxlvt@plt>
mov    %eax,%ebp
movl   $0x0,0xe00(%rbx)
cmp    $0x3,%eax
jl     1143 <apic_clear+0x23>
orb    $0x1,0xdc2(%rbx)
cmp    $0x4,%ebp
jl     115f <apic_clear+0x3f>
orb    $0x1,0xd02(%rbx)
cmp    $0x6,%ebp
jb     115f <apic_clear+0x3f>
orb    $0x1,0xbc2(%rbx)
mov    $0x1,%al
jmp    1161 <apic_clear+0x41>
xor    %eax,%eax
movl   $0x10000,0xc80(%rbx)
movl   $0x10000,0xd40(%rbx)
movl   $0x10000,0xd80(%rbx)
cmp    $0x3,%ebp
jl     11c4 <apic_clear+0xa4>
movl   $0x10000,0xdc0(%rbx)
cmp    $0x4,%ebp
jge    11c9 <apic_clear+0xa9>
test   %al,%al
je     11a1 <apic_clear+0x81>
movl   $0x10000,0xbc0(%rbx)
mov    %rbx,%rdi
call   1040 <apic_is_integrated@plt>
test   %rax,%rax
je     11bd <apic_clear+0x9d>
cmp    $0x4,%ebp
jl     11bd <apic_clear+0x9d>
movl   $0x0,0xa00(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x4,%ebp
jl     1193 <apic_clear+0x73>
movl   $0x10000,0xd00(%rbx)
test   %al,%al
jne    1197 <apic_clear+0x77>
jmp    11a1 <apic_clear+0x81>

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

LLVM IR (-O2):
define void @apic_clear(i32* %0) {
%2 = tail call i32 @apic_get_maxlvt(i32* %0)
%3 = getelementptr inbounds i32, i32* %0, i64 896
store i32 0, i32* %3
%4 = icmp sgt i32 %2, 2
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = getelementptr inbounds i32, i32* %0, i64 880
%7 = load i32, i32* %6
%8 = or i32 %7, 65536
store i32 %8, i32* %6
br label %9
9: ; preds = %5, %1
%10 = getelementptr inbounds i32, i32* %0, i64 800
%11 = getelementptr inbounds i32, i32* %0, i64 848
%12 = getelementptr inbounds i32, i32* %0, i64 864
%13 = icmp sgt i32 %2, 3
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = getelementptr inbounds i32, i32* %0, i64 832
%16 = load i32, i32* %15
%17 = or i32 %16, 65536
store i32 %17, i32* %15
%18 = icmp ugt i32 %2, 5
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = getelementptr inbounds i32, i32* %0, i64 752
%21 = load i32, i32* %20
%22 = or i32 %21, 65536
store i32 %22, i32* %20
br label %23
23: ; preds = %9, %19, %14
%24 = phi i1 [ true, %19 ], [ false, %14 ], [ false, %9 ]
store i32 65536, i32* %10
store i32 65536, i32* %11
store i32 65536, i32* %12
br i1 %4, label %25, label %27
25: ; preds = %23
%26 = getelementptr inbounds i32, i32* %0, i64 880
store i32 65536, i32* %26
br label %27
27: ; preds = %25, %23
br i1 %13, label %28, label %30
28: ; preds = %27
%29 = getelementptr inbounds i32, i32* %0, i64 832
store i32 65536, i32* %29
br label %30
30: ; preds = %28, %27
br i1 %24, label %31, label %33
31: ; preds = %30
%32 = getelementptr inbounds i32, i32* %0, i64 752
store i32 65536, i32* %32
br label %33
33: ; preds = %31, %30
%34 = tail call i64 @apic_is_integrated(i32* %0)
%35 = icmp ne i64 %34, 0
%36 = select i1 %35, i1 %13, i1 false
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = getelementptr inbounds i32, i32* %0, i64 640
store i32 0, i32* %38
br label %39
39: ; preds = %37, %33
ret void
}