#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 */

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int getppid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
void chew_cpu(void) {
  while (1) {
    static volatile char buf[4096];
    for (int i = 0; i < 100; ++i)
      for (size_t j = 0; j < sizeof buf; ++j)
        buf[j] = 0xaa;
    int nullfd = open("/dev/null", O_WRONLY);
    for (int i = 0; i < 100; ++i)
      for (size_t j = 0; j < sizeof buf; ++j)
        buf[j] = 0xbb;
    write(nullfd, (char *)buf, sizeof buf);
    close(nullfd);
    if (getppid() == 1)
      _exit(2);
  }
}


x86 assembly (clang, -O0):
<chew_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    11b2 <chew_cpu+0x62>
movq   $0x0,-0x10(%rbp)
cmpq   $0x1000,-0x10(%rbp)
jae    119f <chew_cpu+0x4f>
mov    -0x10(%rbp),%rcx
lea    0x2ed6(%rip),%rax
movb   $0xaa,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1171 <chew_cpu+0x21>
jmp    11a4 <chew_cpu+0x54>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115f <chew_cpu+0xf>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    1224 <chew_cpu+0xd4>
movq   $0x0,-0x20(%rbp)
cmpq   $0x1000,-0x20(%rbp)
jae    1211 <chew_cpu+0xc1>
mov    -0x20(%rbp),%rcx
lea    0x2e64(%rip),%rax
movb   $0xbb,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e3 <chew_cpu+0x93>
jmp    1216 <chew_cpu+0xc6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d1 <chew_cpu+0x81>
mov    -0x14(%rbp),%edi
lea    0x2e32(%rip),%rsi
mov    $0x1000,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0x0,%al
call   1070 <getppid@plt>
cmp    $0x1,%eax
jne    125a <chew_cpu+0x10a>
mov    $0x2,%edi
call   1030 <_exit@plt>
jmp    1158 <chew_cpu+0x8>

x86 assembly (clang, -O2):
<chew_cpu>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
lea    0x2f00(%rip),%rbx
mov    0x2e71(%rip),%r15
lea    0xe92(%rip),%r14
xchg   %ax,%ax
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0xaa,(%rax,%rbx,1)
movb   $0xaa,0x1(%rax,%rbx,1)
movb   $0xaa,0x2(%rax,%rbx,1)
movb   $0xaa,0x3(%rax,%rbx,1)
movb   $0xaa,0x4(%rax,%rbx,1)
movb   $0xaa,0x5(%rax,%rbx,1)
movb   $0xaa,0x6(%rax,%rbx,1)
movb   $0xaa,0x7(%rax,%rbx,1)
add    $0x8,%rax
cmp    $0x1000,%rax
jne    1180 <chew_cpu+0x30>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1170 <chew_cpu+0x20>
mov    (%r15),%esi
mov    %r14,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0xbb,(%rcx,%rbx,1)
movb   $0xbb,0x1(%rcx,%rbx,1)
movb   $0xbb,0x2(%rcx,%rbx,1)
movb   $0xbb,0x3(%rcx,%rbx,1)
movb   $0xbb,0x4(%rcx,%rbx,1)
movb   $0xbb,0x5(%rcx,%rbx,1)
movb   $0xbb,0x6(%rcx,%rbx,1)
movb   $0xbb,0x7(%rcx,%rbx,1)
add    $0x8,%rcx
cmp    $0x1000,%rcx
jne    11e0 <chew_cpu+0x90>
add    $0x1,%eax
cmp    $0x64,%eax
jne    11d0 <chew_cpu+0x80>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <getppid@plt>
cmp    $0x1,%eax
jne    1170 <chew_cpu+0x20>
mov    $0x2,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@chew_cpu.buf = internal global [4096 x i8] zeroinitializer
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define void @chew_cpu() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
br label %6
6: ; preds = %0, %53
store i32 0, i32* %1
br label %7
7: ; preds = %21, %6
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %24
10: ; preds = %7
store i64 0, i64* %2
br label %11
11: ; preds = %17, %10
%12 = load i64, i64* %2
%13 = icmp ult i64 %12, 4096
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i64, i64* %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %15
store volatile i8 -86, i8* %16
br label %17
17: ; preds = %14
%18 = load i64, i64* %2
%19 = add i64 %18, 1
store i64 %19, i64* %2
br label %11
20: ; preds = %11
br label %21
21: ; preds = %20
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %7
24: ; preds = %7
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 %26, i32* %3
store i32 0, i32* %4
br label %27
27: ; preds = %41, %24
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 100
br i1 %29, label %30, label %44
30: ; preds = %27
store i64 0, i64* %5
br label %31
31: ; preds = %37, %30
%32 = load i64, i64* %5
%33 = icmp ult i64 %32, 4096
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i64, i64* %5
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %35
store volatile i8 -69, i8* %36
br label %37
37: ; preds = %34
%38 = load i64, i64* %5
%39 = add i64 %38, 1
store i64 %39, i64* %5
br label %31
40: ; preds = %31
br label %41
41: ; preds = %40
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %27
44: ; preds = %27
%45 = load i32, i32* %3
%46 = call i32 @write(i32 %45, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 0), i32 4096)
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
%49 = call i32 (...) @getppid()
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @_exit(i32 2)
unreachable
53: ; preds = %44
br label %6
}

LLVM IR (-O2):
@chew_cpu.buf = internal global [4096 x i8] zeroinitializer
@.str = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define void @chew_cpu() {
br label %1
1: ; preds = %9, %0
%2 = phi i32 [ 0, %0 ], [ %10, %9 ]
br label %11
3: ; preds = %6
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %30
6: ; preds = %11
%7 = add nuw nsw i32 %2, 1
%8 = icmp eq i32 %7, 100
br i1 %8, label %3, label %9
9: ; preds = %6, %32
%10 = phi i32 [ %7, %6 ], [ 0, %32 ]
br label %1
11: ; preds = %11, %1
%12 = phi i64 [ 0, %1 ], [ %28, %11 ]
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %12
store volatile i8 -86, i8* %13
%14 = or i64 %12, 1
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %14
store volatile i8 -86, i8* %15
%16 = or i64 %12, 2
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %16
store volatile i8 -86, i8* %17
%18 = or i64 %12, 3
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %18
store volatile i8 -86, i8* %19
%20 = or i64 %12, 4
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %20
store volatile i8 -86, i8* %21
%22 = or i64 %12, 5
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %22
store volatile i8 -86, i8* %23
%24 = or i64 %12, 6
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %24
store volatile i8 -86, i8* %25
%26 = or i64 %12, 7
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %26
store volatile i8 -86, i8* %27
%28 = add nuw nsw i64 %12, 8
%29 = icmp eq i64 %28, 4096
br i1 %29, label %6, label %11
30: ; preds = %3, %37
%31 = phi i32 [ 0, %3 ], [ %38, %37 ]
br label %40
32: ; preds = %37
%33 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 0), i32 4096)
%34 = tail call i32 @close(i32 %5)
%35 = tail call i32 (...) @getppid()
%36 = icmp eq i32 %35, 1
br i1 %36, label %59, label %9
37: ; preds = %40
%38 = add nuw nsw i32 %31, 1
%39 = icmp eq i32 %38, 100
br i1 %39, label %32, label %30
40: ; preds = %40, %30
%41 = phi i64 [ 0, %30 ], [ %57, %40 ]
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %41
store volatile i8 -69, i8* %42
%43 = or i64 %41, 1
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %43
store volatile i8 -69, i8* %44
%45 = or i64 %41, 2
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %45
store volatile i8 -69, i8* %46
%47 = or i64 %41, 3
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %47
store volatile i8 -69, i8* %48
%49 = or i64 %41, 4
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %49
store volatile i8 -69, i8* %50
%51 = or i64 %41, 5
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %51
store volatile i8 -69, i8* %52
%53 = or i64 %41, 6
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %53
store volatile i8 -69, i8* %54
%55 = or i64 %41, 7
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* @chew_cpu.buf, i64 0, i64 %55
store volatile i8 -69, i8* %56
%57 = add nuw nsw i64 %41, 8
%58 = icmp eq i64 %57, 4096
br i1 %58, label %37, label %40
59: ; preds = %32
%60 = tail call i32 @_exit(i32 2)
unreachable
}