#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ok2overwrite();
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char const *);
void check_file(DIR *dp, const char *src) {
  struct dirent *ep = NULL;
  while (1) {
    if ((ep = readdir(dp)) == NULL)
      break;
    if (!strcmp(ep->d_name, src) && !ok2overwrite())
      exit(0);
  }
}


x86 assembly (clang, -O0):
<check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1174 <check_file+0x34>
jmp    11a8 <check_file+0x68>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a3 <check_file+0x63>
mov    $0x0,%al
call   1030 <ok2overwrite@plt>
cmp    $0x0,%eax
jne    11a3 <check_file+0x63>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    1158 <check_file+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
jmp    1153 <check_file+0x13>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     117d <check_file+0x3d>
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1150 <check_file+0x10>
xor    %eax,%eax
call   1030 <ok2overwrite@plt>
test   %eax,%eax
jne    1150 <check_file+0x10>
xor    %edi,%edi
call   1060 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
define void @check_file(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca %struct.dirent*
store i32* %0, i32** %3
store i8* %1, i8** %4
store %struct.dirent* null, %struct.dirent** %5
br label %6
6: ; preds = %2, %23
%7 = load i32*, i32** %3
%8 = call %struct.dirent* @readdir(i32* %7)
store %struct.dirent* %8, %struct.dirent** %5
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %10, label %11
10: ; preds = %6
br label %24
11: ; preds = %6
%12 = load %struct.dirent*, %struct.dirent** %5
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i8*, i8** %4
%16 = call i32 @strcmp(i32 %14, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = call i32 (...) @ok2overwrite()
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %18, %11
br label %6
24: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
define void @check_file(i32* %0, i8* %1) {
%3 = tail call %struct.dirent* @readdir(i32* %0)
%4 = icmp eq %struct.dirent* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2, %16
%6 = phi %struct.dirent* [ %17, %16 ], [ %3, %2 ]
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @strcmp(i32 %8, i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = tail call i32 (...) @ok2overwrite()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %11, %5
%17 = tail call %struct.dirent* @readdir(i32* %0)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %19, label %5
19: ; preds = %16, %2
ret void
}