#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, int, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *strerror(scalar_t__);
int check_no_file(char *base, int nb, int line) {
  struct stat stats;
  int ret;
  char file[128];
  sprintf(file, "%s%d", base, nb);
  ret = lstat(file, &stats);
  if (ret >= 0) {
    printf("%d File %s should not exist\n", line, file);
    return -1;
  }
  if (errno != ENOENT) {
    printf("%d File %s expecting ENOENT %s\n", line, file, strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_no_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe96(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11b0 <check_no_file+0x70>
mov    -0x18(%rbp),%esi
lea    -0xb0(%rbp),%rdx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <check_no_file+0xe1>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%rax
je     121a <check_no_file+0xda>
mov    -0x18(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0xbc(%rbp),%esi
mov    -0xb8(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <check_no_file+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_no_file>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %edx,%ebp
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0xea9(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <lstat@plt>
test   %eax,%eax
js     118c <check_no_file+0x4c>
lea    0xe89(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c1 <check_no_file+0x81>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rdi
mov    0x2e33(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%rdi
je     11c6 <check_no_file+0x86>
call   1060 <strerror@plt>
lea    0xe72(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %ebp,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [29 x i8] c"%d File %s should not exist\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [32 x i8] c"%d File %s expecting ENOENT %s\0A\00"
define i32 @check_no_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca [128 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%16 = call i32 @lstat(i8* %15, %struct.stat* %8)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* %7
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%22 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
store i32 -1, i32* %4
br label %34
23: ; preds = %3
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %7
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%30 = load i64, i64* @errno
%31 = call i8* @strerror(i64 %30)
%32 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %28, i8* %29, i8* %31)
store i32 -1, i32* %4
br label %34
33: ; preds = %23
store i32 0, i32* %4
br label %34
34: ; preds = %33, %27, %19
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [29 x i8] c"%d File %s should not exist\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [32 x i8] c"%d File %s expecting ENOENT %s\0A\00"
define i32 @check_no_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca [128 x i8]
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%9 = call i32 @lstat(i8* %7, %struct.stat* %4)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %7)
br label %20
13: ; preds = %3
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i8* @strerror(i64 %14)
%19 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %2, i8* %7, i8* %18)
br label %20
20: ; preds = %13, %17, %11
%21 = phi i32 [ -1, %11 ], [ -1, %17 ], [ 0, %13 ]
ret i32 %21
}