#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*/ env_destroy(int);
int getenvid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ yield();
void child() {
  int *test0 = (int *)0x500;
  while (1) {
    printf("child: %lx %d\n", test0, *test0);
    *test0 = 1000;
    printf("child: %lx %d\n", test0, *test0);
    test0++;
    yield();
    printf("%d %d %d %d %d %d %d %d %d %d\n", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    sleep(100);
    printf("%u\n", getenvid());
    env_destroy(getenvid());
  }
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x500,%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x3e8,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <yield@plt>
lea    0xe56(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
movl   $0x5,(%rsp)
movl   $0x6,0x8(%rsp)
movl   $0x7,0x10(%rsp)
movl   $0x8,0x18(%rsp)
movl   $0x9,0x20(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1060 <getenvid@plt>
mov    %eax,%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getenvid@plt>
mov    %eax,%edi
call   1030 <env_destroy@plt>
jmp    1161 <child+0x11>

x86 assembly (clang, -O2):
<child>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x500,%ebx
lea    0xe9c(%rip),%r14
lea    0xea4(%rip),%r15
lea    0xebc(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x3e8,(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x4,%rbx
xor    %eax,%eax
call   1040 <yield@plt>
sub    $0x8,%rsp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
xor    %eax,%eax
push   $0x9
push   $0x8
push   $0x7
push   $0x6
push   $0x5
call   1050 <printf@plt>
add    $0x30,%rsp
mov    $0x64,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1060 <getenvid@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getenvid@plt>
mov    %eax,%edi
call   1030 <env_destroy@plt>
jmp    1180 <child+0x30>

LLVM IR (-O0):
@.str = [15 x i8] c"child: %lx %d\0A\00"
@.str.1 = [31 x i8] c"%d %d %d %d %d %d %d %d %d %d\0A\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define void @child() {
%1 = alloca i32*
store i32* inttoptr (i64 1280 to i32*), i32** %1
br label %2
2: ; preds = %0, %2
%3 = load i32*, i32** %1
%4 = load i32*, i32** %1
%5 = load i32, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %3, i32 %5)
%7 = load i32*, i32** %1
store i32 1000, i32* %7
%8 = load i32*, i32** %1
%9 = load i32*, i32** %1
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %8, i32 %10)
%12 = load i32*, i32** %1
%13 = getelementptr inbounds i32, i32* %12, i32 1
store i32* %13, i32** %1
%14 = call i32 (...) @yield()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9)
%16 = call i32 @sleep(i32 100)
%17 = call i32 (...) @getenvid()
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @getenvid()
%20 = call i32 @env_destroy(i32 %19)
br label %2
}

LLVM IR (-O2):
@.str = [15 x i8] c"child: %lx %d\0A\00"
@.str.1 = [31 x i8] c"%d %d %d %d %d %d %d %d %d %d\0A\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define void @child() {
br label %1
1: ; preds = %1, %0
%2 = phi i32* [ inttoptr (i64 1280 to i32*), %0 ], [ %6, %1 ]
%3 = load i32, i32* %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %2, i32 %3)
store i32 1000, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %2, i32 1000)
%6 = getelementptr inbounds i32, i32* %2, i64 1
%7 = tail call i32 (...) @yield()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9)
%9 = tail call i32 @sleep(i32 100)
%10 = tail call i32 (...) @getenvid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @getenvid()
%13 = tail call i32 @env_destroy(i32 %12)
br label %1
}