#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*/ Spin(int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int getpid();
int *malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  int *p = malloc(sizeof(int));
  assert(p != NULL);
  int pid = getpid();
  printf("Process: (%d) :: Memory address of p: %08x\n", pid, (unsigned)p);
  *p = 0;
  for (;;) {
    Spin(1);
    (*p)++;
    printf("Process: (%d) :: Contents: %d\n", pid, *p);
  }
  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)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x1,%edi
call   1070 <Spin@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
jmp    11af <main+0x5f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
lea    0xe81(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
movl   $0x0,(%rbx)
lea    0xe97(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   1070 <Spin@plt>
mov    (%rbx),%edx
add    $0x1,%edx
mov    %edx,(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
jmp    11a0 <main+0x50>

LLVM IR (-O0):
@.str = [44 x i8] c"Process: (%d) :: Memory address of p: %08x\0A\00"
@.str.1 = [31 x i8] c"Process: (%d) :: Contents: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @malloc(i32 4)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 (...) @getpid()
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = load i32*, i32** %6
%16 = ptrtoint i32* %15 to i32
%17 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16)
%18 = load i32*, i32** %6
store i32 0, i32* %18
br label %19
19: ; preds = %19, %2
%20 = call i32 @Spin(i32 1)
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = load i32, i32* %7
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %26)
br label %19
}

LLVM IR (-O2):
@.str = [44 x i8] c"Process: (%d) :: Memory address of p: %08x\0A\00"
@.str.1 = [31 x i8] c"Process: (%d) :: Contents: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 4)
%4 = icmp ne i32* %3, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 (...) @getpid()
%8 = ptrtoint i32* %3 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %11, %2
%12 = tail call i32 @Spin(i32 1)
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %14)
br label %11
}