#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 pid_t;

/* Variables and functions */
int RAND_MAX;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ random();
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[], char *envp[]) {
  int variable = 12;
  pid_t pid = getpid();
  printf("PID: %u", pid);
  printf(" variable address is 0x%lx - %ld bytes\n", (unsigned long)&variable,
         sizeof(int));
  printf(">> Press any key to change value\n");
  int is_first_time = 1;
  while (variable != 0xdeadbeef) {
    if (!is_first_time) {
      variable = (int)random() / RAND_MAX;
    } else {
      is_first_time = 0;
    }
    printf(" Value is %d", variable);
    fflush(stdout);
    getchar();
  }
  printf("0xdeadbeef detected. Exiting\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0xdeadbeef,-0x1c(%rbp)
je     121a <main+0xca>
cmpl   $0x0,-0x24(%rbp)
jne    11e8 <main+0x98>
mov    $0x0,%al
call   1060 <random@plt>
mov    0x2e0b(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x1c(%rbp)
jmp    11ef <main+0x9f>
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
jmp    11b8 <main+0x68>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0xc,0xc(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
cmp    $0xdeadbeef,%esi
je     1234 <main+0xd4>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e0b(%rip),%r14
mov    (%r14),%edi
call   1080 <fflush@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmpl   $0xdeadbeef,0xc(%rsp)
de
je     1234 <main+0xd4>
mov    0x2dfb(%rip),%r15
lea    0xe3c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <random@plt>
cltd
idivl  (%r15)
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
call   1080 <fflush@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmpl   $0xdeadbeef,0xc(%rsp)
de
jne    1200 <main+0xa0>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"PID: %u\00"
@.str.1 = [40 x i8] c" variable address is 0x%lx - %ld bytes\0A\00"
@.str.2 = [34 x i8] c">> Press any key to change value\0A\00"
@RAND_MAX = global i32 0
@.str.3 = [13 x i8] c" Value is %d\00"
@stdout = global i32 0
@.str.4 = [30 x i8] c"0xdeadbeef detected. Exiting\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 12, i32* %8
%11 = call i32 (...) @getpid()
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = ptrtoint i32* %8 to i64
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 4)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %10
br label %17
17: ; preds = %29, %3
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, -559038737
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i32, i32* %10
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = call i64 (...) @random()
%25 = trunc i64 %24 to i32
%26 = load i32, i32* @RAND_MAX
%27 = sdiv i32 %25, %26
store i32 %27, i32* %8
br label %29
28: ; preds = %20
store i32 0, i32* %10
br label %29
29: ; preds = %28, %23
%30 = load i32, i32* %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = call i32 (...) @getchar()
br label %17
35: ; preds = %17
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"PID: %u\00"
@.str.1 = [40 x i8] c" variable address is 0x%lx - %ld bytes\0A\00"
@RAND_MAX = global i32 0
@.str.3 = [13 x i8] c" Value is %d\00"
@stdout = global i32 0
@str = [33 x i8] c">> Press any key to change value\00"
@str.5 = [29 x i8] c"0xdeadbeef detected. Exiting\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = ptrtoint i32* %4 to i64
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %8, i64 4)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -559038737
br i1 %12, label %31, label %13
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = call i32 (...) @getchar()
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, -559038737
br i1 %19, label %31, label %20
20: ; preds = %13, %20
%21 = call i64 (...) @random()
%22 = trunc i64 %21 to i32
%23 = load i32, i32* @RAND_MAX
%24 = sdiv i32 %22, %23
store i32 %24, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = call i32 (...) @getchar()
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, -559038737
br i1 %30, label %31, label %20
31: ; preds = %20, %13, %3
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}