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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char const *);
int checkIdPw(const char *id, const char *pw) {
  DIR *dir;
  struct dirent *dir_ent;
  char _pw[80];
  FILE *f;
  dir = opendir(".");
  if (dir == NULL) {
    closedir(dir);
    return -1;
  }
  while (dir_ent = readdir(dir)) {
    if (strcmp(dir_ent->d_name, id) == 0) {
      f = fopen(dir_ent->d_name, "r");
      if (f == NULL) {
        closedir(dir);
        return -1;
      }
      fscanf(f, "%s", _pw);
      if (strcmp(_pw, pw) == 0) {
        fclose(f);
        closedir(dir);
        return 1;
      }
      fclose(f);
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<checkIdPw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe76(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <checkIdPw+0x43>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <checkIdPw+0x126>
jmp    11b8 <checkIdPw+0x48>
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1286 <checkIdPw+0x116>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1281 <checkIdPw+0x111>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1226 <checkIdPw+0xb6>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <checkIdPw+0x126>
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xdcc(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1275 <checkIdPw+0x105>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    1296 <checkIdPw+0x126>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11b8 <checkIdPw+0x48>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkIdPw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
lea    0xe73(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1243 <checkIdPw+0xd3>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1237 <checkIdPw+0xc7>
mov    %rax,%r13
lea    0x10(%rsp),%r12
jmp    11d0 <checkIdPw+0x60>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1237 <checkIdPw+0xc7>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11c0 <checkIdPw+0x50>
mov    0x0(%r13),%rdi
lea    0xe16(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125e <checkIdPw+0xee>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xe01(%rip),%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <fclose@plt>
test   %rbx,%rbx
jne    11c0 <checkIdPw+0x50>
mov    %r14,%rdi
call   1060 <closedir@plt>
mov    $0x1,%eax
jmp    124f <checkIdPw+0xdf>
mov    %r14,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    124f <checkIdPw+0xdf>
xor    %edi,%edi
call   1060 <closedir@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    1245 <checkIdPw+0xd5>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @checkIdPw(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca [80 x i8]
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = call i32 @closedir(i32* %14)
store i32 -1, i32* %3
br label %58
16: ; preds = %2
br label %17
17: ; preds = %54, %16
%18 = load i32*, i32** %6
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %7
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %55
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %7
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8*, i8** %4
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %54
28: ; preds = %21
%29 = load %struct.dirent*, %struct.dirent** %7
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %9
%33 = load i32*, i32** %9
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32*, i32** %6
%37 = call i32 @closedir(i32* %36)
store i32 -1, i32* %3
br label %58
38: ; preds = %28
%39 = load i32*, i32** %9
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%41 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%43 = load i8*, i8** %5
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %38
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %6
%50 = call i32 @closedir(i32* %49)
store i32 1, i32* %3
br label %58
51: ; preds = %38
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %21
br label %17
55: ; preds = %17
%56 = load i32*, i32** %6
%57 = call i32 @closedir(i32* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %55, %46, %35, %13
%59 = load i32, i32* %3
ret i32 %59
}

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