#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*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
int checkId(const char *id) {
  DIR *dir;
  struct dirent *dir_ent;
  dir = opendir(".");
  if (dir == NULL) {
    closedir(dir);
    return -1;
  }
  while (dir_ent = readdir(dir)) {
    if (strcmp(dir_ent->d_name, id) == 0) {
      closedir(dir);
      return 1;
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<checkId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117c <checkId+0x3c>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <checkId+0x9b>
jmp    1181 <checkId+0x41>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cb <checkId+0x8b>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c6 <checkId+0x86>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    11db <checkId+0x9b>
jmp    1181 <checkId+0x41>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkId>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     118b <checkId+0x4b>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1199 <checkId+0x59>
mov    (%rax),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1160 <checkId+0x20>
mov    %rbx,%rdi
call   1040 <closedir@plt>
mov    $0x1,%eax
jmp    11a3 <checkId+0x63>
xor    %edi,%edi
call   1040 <closedir@plt>
mov    $0xffffffff,%eax
jmp    11a3 <checkId+0x63>
mov    %rbx,%rdi
call   1040 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
define i32 @checkId(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
store i8* %0, i8** %3
%6 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32*, i32** %4
%11 = call i32 @closedir(i32* %10)
store i32 -1, i32* %2
br label %31
12: ; preds = %1
br label %13
13: ; preds = %27, %12
%14 = load i32*, i32** %4
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %5
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %5
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i8*, i8** %3
%22 = call i64 @strcmp(i32 %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32*, i32** %4
%26 = call i32 @closedir(i32* %25)
store i32 1, i32* %2
br label %31
27: ; preds = %17
br label %13
28: ; preds = %13
%29 = load i32*, i32** %4
%30 = call i32 @closedir(i32* %29)
store i32 0, i32* %2
br label %31
31: ; preds = %28, %24, %9
%32 = load i32, i32* %2
ret i32 %32
}

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