#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*/ do_nothing(int /*<<< orphan*/);
int /*<<< orphan*/ do_nothing2();
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ getpid();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  int n = 99;
  while (1) {
    char *cp = malloc(1234);
    free(cp);
    printf("pid: %d %p ", (int)getpid(), &cp);
    fflush(stdout);
    system("uptime");
    system("head /proc/dtrace/fasttrap");
    sleep(1);
    if (argc > 1) {
      char buf[1024];
      printf("Ready: ");
      fgets(buf, sizeof buf, stdin);
      do_nothing2();
    } else
      do_nothing(n++);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x63,-0x14(%rbp)
mov    $0x4d2,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xe05(%rip),%rdi
call   1050 <system@plt>
lea    0xe00(%rip),%rdi
call   1050 <system@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1260 <main+0xc0>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    $0x0,%al
call   1070 <do_nothing2@plt>
jmp    1270 <main+0xd0>
mov    -0x14(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
call   1080 <do_nothing@plt>
jmp    11c0 <main+0x20>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edi,%r15d
mov    $0x63,%eax
mov    %rax,(%rsp)
lea    0xe3c(%rip),%rbp
lea    0x8(%rsp),%rbx
mov    0x2e08(%rip),%r14
lea    0xe35(%rip),%r13
jmp    1206 <main+0x66>
nopl   0x0(%rax)
mov    %r15d,%r12d
mov    %r13,%r15
mov    %r14,%r13
mov    (%rsp),%rdi
lea    0x1(%rdi),%r14d
call   1080 <do_nothing@plt>
mov    %r14d,%eax
mov    %rax,(%rsp)
mov    %r13,%r14
mov    %r15,%r13
mov    %r12d,%r15d
lea    0xe06(%rip),%r12
mov    $0x4d2,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%edi
call   10b0 <fflush@plt>
mov    %r13,%rdi
call   1050 <system@plt>
mov    %r12,%rdi
call   1050 <system@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
cmp    $0x2,%r15d
jl     11e0 <main+0x40>
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
xor    %eax,%eax
call   1070 <do_nothing2@plt>
jmp    120d <main+0x6d>

LLVM IR (-O0):
@.str = [12 x i8] c"pid: %d %p \00"
@stdout = global i32 0
@.str.1 = [7 x i8] c"uptime\00"
@.str.2 = [27 x i8] c"head /proc/dtrace/fasttrap\00"
@.str.3 = [8 x i8] c"Ready: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 99, i32* %6
br label %9
9: ; preds = %2, %33
%10 = call i8* @malloc(i32 1234)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @free(i8* %11)
%13 = call i64 (...) @getpid()
%14 = trunc i64 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14, i8** %7)
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @sleep(i32 1)
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %29
23: ; preds = %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %25, i32 1024, i32 %26)
%28 = call i32 (...) @do_nothing2()
br label %33
29: ; preds = %9
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = call i32 @do_nothing(i32 %30)
br label %33
33: ; preds = %29, %23
br label %9
}

LLVM IR (-O2):
@.str = [12 x i8] c"pid: %d %p \00"
@stdout = global i32 0
@.str.1 = [7 x i8] c"uptime\00"
@.str.2 = [27 x i8] c"head /proc/dtrace/fasttrap\00"
@.str.3 = [8 x i8] c"Ready: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = bitcast i8** %3 to i8*
%6 = icmp sgt i32 %0, 1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %8
8: ; preds = %28, %2
%9 = phi i32 [ 99, %2 ], [ %29, %28 ]
%10 = call dereferenceable_or_null(1234) i8* @malloc(i32 1234)
store i8* %10, i8** %3
%11 = call i32 @free(i8* %10)
%12 = call i64 (...) @getpid()
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i8** %3)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @sleep(i32 1)
br i1 %6, label %20, label %25
20: ; preds = %8
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %7, i32 1024, i32 %22)
%24 = call i32 (...) @do_nothing2()
br label %28
25: ; preds = %8
%26 = add nsw i32 %9, 1
%27 = call i32 @do_nothing(i32 %9)
br label %28
28: ; preds = %25, %20
%29 = phi i32 [ %9, %20 ], [ %26, %25 ]
br label %8
}