#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 clock();
void main(void) {
  (*(volatile uint8_t *)0x50c0) = 0x00;
  (*(volatile uint8_t *)0x50c4) |= 0x02;
  (*(volatile uint8_t *)0x52c1) = 0x3e;
  (*(volatile uint8_t *)0x52c2) = 0x80;
  (*(volatile uint8_t *)0x52b0) = 0x01;
  (*(volatile uint8_t *)0x5016) = 0x80;
  (*(volatile uint8_t *)0x5017) = 0x80;
  (*(volatile uint8_t *)0x500c) = 0x80;
  (*(volatile uint8_t *)0x500d) = 0x80;
  for (;;) {
    (*(volatile uint8_t *)0x5014) &= 0x7f;
    if (clock() % 1000 <= 500)
      (*(volatile uint8_t *)0x5014) |= 0x80;
    (*(volatile uint8_t *)0x500a) &= 0x7f;
    if (clock() % 2000 <= 1000)
      (*(volatile uint8_t *)0x500a) |= 0x80;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
mov    $0x50c0,%eax
movl   $0x0,(%rax)
mov    $0x50c4,%eax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    $0x50c4,%eax
mov    %ecx,(%rax)
mov    $0x52c1,%eax
movl   $0x3e,(%rax)
mov    $0x52c2,%eax
movl   $0x80,(%rax)
mov    $0x52b0,%eax
movl   $0x1,(%rax)
mov    $0x5016,%eax
movl   $0x80,(%rax)
mov    $0x5017,%eax
movl   $0x80,(%rax)
mov    $0x500c,%eax
movl   $0x80,(%rax)
mov    $0x500d,%eax
movl   $0x80,(%rax)
mov    $0x5014,%eax
mov    (%rax),%ecx
and    $0x7f,%ecx
mov    $0x5014,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <clock@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cmp    $0x1f4,%edx
jg     11bd <main+0xad>
mov    $0x5014,%eax
mov    (%rax),%ecx
or     $0x80,%ecx
mov    $0x5014,%eax
mov    %ecx,(%rax)
mov    $0x500a,%eax
mov    (%rax),%ecx
and    $0x7f,%ecx
mov    $0x500a,%eax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1030 <clock@plt>
mov    $0x7d0,%ecx
cltd
idiv   %ecx
cmp    $0x3e8,%edx
jg     11fd <main+0xed>
mov    $0x500a,%eax
mov    (%rax),%ecx
or     $0x80,%ecx
mov    $0x500a,%eax
mov    %ecx,(%rax)
jmp    117d <main+0x6d>

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x0,0x50c0
orl    $0x2,0x50c4
02
movl   $0x3e,0x52c1
movl   $0x80,0x52c2
movl   $0x1,0x52b0
movl   $0x80,0x5016
movl   $0x80,0x5017
movl   $0x80,0x500c
movl   $0x80,0x500d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
andl   $0x7f,0x5014
7f
xor    %eax,%eax
call   1030 <clock@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x1f4,%eax
jg     11bf <main+0xaf>
orl    $0x80,0x5014
andl   $0x7f,0x500a
7f
xor    %eax,%eax
call   1030 <clock@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x7d0,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x3e8,%eax
jg     1180 <main+0x70>
orl    $0x80,0x500a
jmp    1180 <main+0x70>

LLVM IR (-O0):
define void @main() {
store volatile i32 0, i32* inttoptr (i64 20672 to i32*)
%1 = load volatile i32, i32* inttoptr (i64 20676 to i32*)
%2 = or i32 %1, 2
store volatile i32 %2, i32* inttoptr (i64 20676 to i32*)
store volatile i32 62, i32* inttoptr (i64 21185 to i32*)
store volatile i32 128, i32* inttoptr (i64 21186 to i32*)
store volatile i32 1, i32* inttoptr (i64 21168 to i32*)
store volatile i32 128, i32* inttoptr (i64 20502 to i32*)
store volatile i32 128, i32* inttoptr (i64 20503 to i32*)
store volatile i32 128, i32* inttoptr (i64 20492 to i32*)
store volatile i32 128, i32* inttoptr (i64 20493 to i32*)
br label %3
3: ; preds = %21, %0
%4 = load volatile i32, i32* inttoptr (i64 20500 to i32*)
%5 = and i32 %4, 127
store volatile i32 %5, i32* inttoptr (i64 20500 to i32*)
%6 = call i32 (...) @clock()
%7 = srem i32 %6, 1000
%8 = icmp sle i32 %7, 500
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load volatile i32, i32* inttoptr (i64 20500 to i32*)
%11 = or i32 %10, 128
store volatile i32 %11, i32* inttoptr (i64 20500 to i32*)
br label %12
12: ; preds = %9, %3
%13 = load volatile i32, i32* inttoptr (i64 20490 to i32*)
%14 = and i32 %13, 127
store volatile i32 %14, i32* inttoptr (i64 20490 to i32*)
%15 = call i32 (...) @clock()
%16 = srem i32 %15, 2000
%17 = icmp sle i32 %16, 1000
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load volatile i32, i32* inttoptr (i64 20490 to i32*)
%20 = or i32 %19, 128
store volatile i32 %20, i32* inttoptr (i64 20490 to i32*)
br label %21
21: ; preds = %18, %12
br label %3
}

LLVM IR (-O2):
define void @main() {
store volatile i32 0, i32* inttoptr (i64 20672 to i32*)
%1 = load volatile i32, i32* inttoptr (i64 20676 to i32*)
%2 = or i32 %1, 2
store volatile i32 %2, i32* inttoptr (i64 20676 to i32*)
store volatile i32 62, i32* inttoptr (i64 21185 to i32*)
store volatile i32 128, i32* inttoptr (i64 21186 to i32*)
store volatile i32 1, i32* inttoptr (i64 21168 to i32*)
store volatile i32 128, i32* inttoptr (i64 20502 to i32*)
store volatile i32 128, i32* inttoptr (i64 20503 to i32*)
store volatile i32 128, i32* inttoptr (i64 20492 to i32*)
store volatile i32 128, i32* inttoptr (i64 20493 to i32*)
br label %3
3: ; preds = %21, %0
%4 = load volatile i32, i32* inttoptr (i64 20500 to i32*)
%5 = and i32 %4, 127
store volatile i32 %5, i32* inttoptr (i64 20500 to i32*)
%6 = tail call i32 (...) @clock()
%7 = srem i32 %6, 1000
%8 = icmp slt i32 %7, 501
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load volatile i32, i32* inttoptr (i64 20500 to i32*)
%11 = or i32 %10, 128
store volatile i32 %11, i32* inttoptr (i64 20500 to i32*)
br label %12
12: ; preds = %9, %3
%13 = load volatile i32, i32* inttoptr (i64 20490 to i32*)
%14 = and i32 %13, 127
store volatile i32 %14, i32* inttoptr (i64 20490 to i32*)
%15 = tail call i32 (...) @clock()
%16 = srem i32 %15, 2000
%17 = icmp slt i32 %16, 1001
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load volatile i32, i32* inttoptr (i64 20490 to i32*)
%20 = or i32 %19, 128
store volatile i32 %20, i32* inttoptr (i64 20490 to i32*)
br label %21
21: ; preds = %18, %12
br label %3
}