#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 access(char *, int);
int getpid();
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  int ret;
  int i;
  char buf[1024];
  memset(buf, 'a', sizeof buf);
  for (i = 0;; i++) {
    printf("pid=%d %d: doing access\n", getpid(), i);
    if ((ret = access("/tmp/xxxx", 2)) < 0) {
      printf("access ret=%d ", ret);
      perror("");
    }
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x2,%esi
call   1060 <access@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11e3 <main+0x83>
mov    -0x8(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118f <main+0x2f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xe78(%rip),%r14
lea    0xe8a(%rip),%rbx
lea    0xe8d(%rip),%r15
lea    0xe7b(%rip),%r12
xor    %ebp,%ebp
jmp    11bd <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x5,%edi
call   1080 <sleep@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <access@plt>
test   %eax,%eax
jns    11b0 <main+0x50>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1070 <perror@plt>
jmp    11b0 <main+0x50>

LLVM IR (-O0):
@.str = [25 x i8] c"pid=%d %d: doing access\0A\00"
@.str.1 = [10 x i8] c"/tmp/xxxx\00"
@.str.2 = [15 x i8] c"access ret=%d \00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i8 signext 97, i32 1024)
store i32 0, i32* %3
br label %7
7: ; preds = %19, %0
%8 = call i32 (...) @getpid()
%9 = load i32, i32* %3
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = call i32 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i32, i32* %2
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %13, %7
%18 = call i32 @sleep(i32 5)
br label %19
19: ; preds = %17
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %7
}

LLVM IR (-O2):
@.str = [25 x i8] c"pid=%d %d: doing access\0A\00"
@.str.1 = [10 x i8] c"/tmp/xxxx\00"
@.str.2 = [15 x i8] c"access ret=%d \00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i8 signext 97, i32 1024)
br label %4
4: ; preds = %13, %0
%5 = phi i32 [ 0, %0 ], [ %15, %13 ]
%6 = call i32 (...) @getpid()
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %5)
%8 = call i32 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%12 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %10, %4
%14 = call i32 @sleep(i32 5)
%15 = add nuw nsw i32 %5, 1
br label %4
}