#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
void checknot(const char *d, const char *f) {
  int fd;
  char n[512];
  sprintf(n, "%s/%s", d, f);
  fd = open(n, 0);
  if (fd >= 0) {
    fprintf(stderr, "test-lab-3-c: open(%s) succeeded for deleted file\n", n);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<checknot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe97(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11af <checknot+0x6f>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checknot>:
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xeab(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <open@plt>
test   %eax,%eax
jns    1177 <checknot+0x37>
add    $0x200,%rsp
pop    %rbx
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %rsp,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"test-lab-3-c: open(%s) succeeded for deleted file\0A\00"
define void @checknot(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 @open(i8* %11, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"test-lab-3-c: open(%s) succeeded for deleted file\0A\00"
define void @checknot(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%6 = call i32 @open(i8* %4, i32 0)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
ret void
}