#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*/ F_OK;
int O_CREAT;
int O_NOFOLLOW;
int O_RDWR;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
void touch(const char *name) {
  if (access("/tmp/grading", F_OK) < 0)
    return;
  char pn[1024];
  snprintf(pn, 1024, "/tmp/%s", name);
  int fd = open(pn, O_RDWR | O_CREAT | O_NOFOLLOW, 0666);
  if (fd >= 0)
    close(fd);
}


x86 assembly (clang, -O0):
<touch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    1173 <touch+0x33>
jmp    11d9 <touch+0x99>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xe83(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jl     11d9 <touch+0x99>
mov    -0x414(%rbp),%edi
call   1040 <close@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touch>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
js     11b4 <touch+0x74>
lea    0xe9f(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
mov    0x2e50(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e56(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11b4 <touch+0x74>
mov    %eax,%edi
call   1040 <close@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/grading\00"
@F_OK = global i32 0
@.str.1 = [8 x i8] c"/tmp/%s\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_NOFOLLOW = global i32 0
define void @touch(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @F_OK
%6 = call i64 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %25
9: ; preds = %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @snprintf(i8* %10, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_NOFOLLOW
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %13, i32 %18, i32 438)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %9
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
br label %25
25: ; preds = %8, %22, %9
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/grading\00"
@F_OK = global i32 0
@.str.1 = [8 x i8] c"/tmp/%s\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_NOFOLLOW = global i32 0
define void @touch(i8* %0) {
%2 = alloca [1024 x i8]
%3 = load i32, i32* @F_OK
%4 = tail call i64 @access(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @O_NOFOLLOW
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %7, i32 %13, i32 438)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %6
%17 = call i32 @close(i32 %14)
br label %18
18: ; preds = %16, %6
br label %19
19: ; preds = %1, %18
ret void
}