#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*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getenv(char *);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
void test_pause() {
  static char trickFile[1024] = "";
  static char pid[10] = "";
  if (trickFile[0] == '\0') {
    strcpy(trickFile, getenv("HOME"));
    strcat(trickFile, "/");
    strcat(trickFile, "HOLD_IO_");
    sprintf(pid, "%d", getpid());
    strcat(trickFile, pid);
  }
  while (access(trickFile, R_OK) == 0) {
    fprintf(stderr, "sleeping\n");
    fflush(stderr);
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<test_pause>:
push   %rbp
mov    %rsp,%rbp
movsbl 0x2ee5(%rip),%eax
cmp    $0x0,%eax
jne    1213 <test_pause+0x83>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%esi
lea    0x2ec7(%rip),%rdi
call   1040 <strcpy@plt>
lea    0x2ebb(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1090 <strcat@plt>
lea    0x2ea8(%rip),%rdi
lea    0xe28(%rip),%rsi
call   1090 <strcat@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edx
lea    0x328c(%rip),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <sprintf@plt>
lea    0x2e79(%rip),%rdi
lea    0x3272(%rip),%rsi
call   1090 <strcat@plt>
jmp    1218 <test_pause+0x88>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
lea    0x2e58(%rip),%rdi
call   1080 <access@plt>
cmp    $0x0,%rax
jne    1269 <test_pause+0xd9>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    1218 <test_pause+0x88>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pause>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,0x2ee1(%rip)
jne    1206 <test_pause+0x76>
lea    0xe58(%rip),%rdi
call   1030 <getenv@plt>
lea    0x2ecc(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
lea    0xe40(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
lea    0xe33(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0x3296(%rip),%rbx
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    0x2dcb(%rip),%r15
mov    (%r15),%esi
lea    0x2e69(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
jne    126b <test_pause+0xdb>
mov    0x2db8(%rip),%rbx
lea    0xde4(%rip),%r14
lea    0x2e4a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%edi
mov    %r14,%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    (%r15),%esi
mov    %r12,%rdi
call   1080 <access@plt>
test   %rax,%rax
je     1240 <test_pause+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@test_pause.trickFile = internal global [1024 x i8] zeroinitializer
@test_pause.pid = internal global [10 x i8] zeroinitializer
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"HOLD_IO_\00"
@.str.3 = [3 x i8] c"%d\00"
@R_OK = global i32 0
@stderr = global i32 0
@.str.4 = [10 x i8] c"sleeping\0A\00"
define void @test_pause() {
%1 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0)
%2 = sext i8 %1 to i32
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %0
%5 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i32 %5)
%7 = call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (...) @getpid()
%10 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_pause.pid, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_pause.pid, i64 0, i64 0))
br label %12
12: ; preds = %4, %0
br label %13
13: ; preds = %17, %12
%14 = load i32, i32* @R_OK
%15 = call i64 @access(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 @fflush(i32 %20)
%22 = call i32 @sleep(i32 1)
br label %13
23: ; preds = %13
ret void
}

LLVM IR (-O2):
@test_pause.trickFile = internal global [1024 x i8] zeroinitializer
@test_pause.pid = internal global [10 x i8] zeroinitializer
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"HOLD_IO_\00"
@.str.3 = [3 x i8] c"%d\00"
@R_OK = global i32 0
@stderr = global i32 0
@.str.4 = [10 x i8] c"sleeping\0A\00"
define void @test_pause() {
%1 = load i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0)
%2 = icmp eq i8 %1, 0
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i32 %4)
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @test_pause.pid, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = tail call i32 @strcat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @test_pause.pid, i64 0, i64 0))
br label %11
11: ; preds = %3, %0
%12 = load i32, i32* @R_OK
%13 = tail call i64 @access(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11, %15
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = tail call i32 @fflush(i32 %18)
%20 = tail call i32 @sleep(i32 1)
%21 = load i32, i32* @R_OK
%22 = tail call i64 @access(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @test_pause.trickFile, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %15, label %24
24: ; preds = %15, %11
ret void
}