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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char volatile *,
                           char volatile *);
int /*<<< orphan*/ heap_loop(int);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  volatile char MARKER_START, MARKER_END;
  FILE *marker_fp = fopen("simpleloop.marker", "w");
  if (marker_fp == NULL) {
    perror("Couldn't open marker file:");
    exit(1);
  }
  fprintf(marker_fp, "%p %p", &MARKER_START, &MARKER_END);
  fclose(marker_fp);
  MARKER_START = 33;
  heap_loop(10000);
  MARKER_END = 34;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <main+0x4e>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
lea    -0x11(%rbp),%rdx
lea    -0x12(%rbp),%rcx
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movb   $0x21,-0x11(%rbp)
mov    $0x2710,%edi
call   1080 <heap_loop@plt>
movb   $0x22,-0x12(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11bd <main+0x5d>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
lea    0xf(%rsp),%rdx
lea    0xe(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movb   $0x21,0xf(%rsp)
mov    $0x2710,%edi
call   1080 <heap_loop@plt>
movb   $0x22,0xe(%rsp)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe50(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"simpleloop.marker\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [27 x i8] c"Couldn't open marker file:\00"
@.str.3 = [6 x i8] c"%p %p\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %8
%17 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7)
%18 = load i32*, i32** %8
%19 = call i32 @fclose(i32* %18)
store volatile i8 33, i8* %6
%20 = call i32 @heap_loop(i32 10000)
store volatile i8 34, i8* %7
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"simpleloop.marker\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [27 x i8] c"Couldn't open marker file:\00"
@.str.3 = [6 x i8] c"%p %p\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca i8
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %4)
%12 = call i32 @fclose(i32* %5)
store volatile i8 33, i8* %3
%13 = call i32 @heap_loop(i32 10000)
store volatile i8 34, i8* %4
ret i32 0
}