#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *crypt(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ strtok(char *, char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "syntax: <encrypted file>\n");
    return 0;
  }
  FILE *encrypt = fopen(argv[1], "r");
  char encryptedLine[200];
  char salt[14];
  char hash[99];
  char username[9];
  char passguess[100];
  while (fgets(encryptedLine, 220, encrypt)) {
    strncpy(salt, &encryptedLine[9], 13);
    salt[13] = '\0';
    strncpy(hash, &encryptedLine[9], 98);
    hash[98] = '\0';
    FILE *guesses = fopen("guesses.txt", "r");
    while (fgets(passguess, 100, guesses)) {
      strtok(passguess, "\n");
      char *cryptoutput = crypt(passguess, salt);
      if (!strcmp(hash, cryptoutput)) {
        strncpy(username, encryptedLine, 8);
        username[8] = '\0';
        printf("%s\n", username);
        break;
      }
    }
    fclose(guesses);
  }
  fclose(encrypt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d4 <main+0x44>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1333 <main+0x1a3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xdc,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1323 <main+0x193>
lea    -0xee(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
add    $0x9,%rsi
mov    $0xd,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0xe1(%rbp)
lea    -0x160(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
add    $0x9,%rsi
mov    $0x62,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0xfe(%rbp)
lea    0xdc4(%rip),%rdi
lea    0xdbb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1d8(%rbp)
lea    -0x1d0(%rbp),%rdi
mov    -0x1d8(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1312 <main+0x182>
lea    -0x1d0(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10b0 <strtok@plt>
lea    -0x1d0(%rbp),%rdi
lea    -0xee(%rbp),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x1e0(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x1e0(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    130d <main+0x17d>
lea    -0x169(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x161(%rbp)
lea    -0x169(%rbp),%rsi
lea    0xd25(%rip),%rdi
call   1060 <printf@plt>
jmp    1312 <main+0x182>
jmp    126b <main+0xdb>
mov    -0x1d8(%rbp),%rdi
call   1050 <fclose@plt>
jmp    11ec <main+0x5c>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1c8,%rsp
cmp    $0x2,%edi
jne    12e3 <main+0x153>
mov    0x8(%rsi),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
lea    0x20(%rsp),%rdi
mov    $0xdc,%esi
mov    %rax,(%rsp)
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12fa <main+0x16a>
lea    0x29(%rsp),%r15
lea    0x12(%rsp),%r12
lea    0xf0(%rsp),%rbx
lea    0x160(%rsp),%r13
lea    0xe1e(%rip),%rbp
jmp    1224 <main+0x94>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0x20(%rsp),%rdi
mov    $0xdc,%esi
mov    (%rsp),%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12fa <main+0x16a>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0xd,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x1f(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x62,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x152(%rsp)
lea    0xdc4(%rip),%rdi
lea    0xdbb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10b0 <strtok@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <crypt@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    1270 <main+0xe0>
lea    0x9(%rsp),%r15
mov    %r15,%rdi
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x11(%rsp)
lea    0xd57(%rip),%rdi
mov    %r15,%rsi
lea    0x29(%rsp),%r15
call   1060 <printf@plt>
jmp    1200 <main+0x70>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd0d(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1303 <main+0x173>
mov    (%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"syntax: <encrypted file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"guesses.txt\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [200 x i8]
%8 = alloca [14 x i8]
%9 = alloca [99 x i8]
%10 = alloca [9 x i8]
%11 = alloca [100 x i8]
%12 = alloca i32*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %68
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
br label %24
24: ; preds = %62, %19
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i64 @fgets(i8* %25, i32 220, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %65
29: ; preds = %24
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 9
%32 = call i32 @strncpy(i8* %30, i8* %31, i32 13)
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 13
store i8 0, i8* %33
%34 = getelementptr inbounds [99 x i8], [99 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 9
%36 = call i32 @strncpy(i8* %34, i8* %35, i32 98)
%37 = getelementptr inbounds [99 x i8], [99 x i8]* %9, i64 0, i64 98
store i8 0, i8* %37
%38 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %12
br label %39
39: ; preds = %61, %29
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%41 = load i32*, i32** %12
%42 = call i64 @fgets(i8* %40, i32 100, i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %39
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%46 = call i32 @strtok(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%48 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%49 = call i8* @crypt(i8* %47, i8* %48)
store i8* %49, i8** %13
%50 = getelementptr inbounds [99 x i8], [99 x i8]* %9, i64 0, i64 0
%51 = load i8*, i8** %13
%52 = call i32 @strcmp(i8* %50, i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %61, label %54
54: ; preds = %44
%55 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%56 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%57 = call i32 @strncpy(i8* %55, i8* %56, i32 8)
%58 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 8
store i8 0, i8* %58
%59 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %62
61: ; preds = %44
br label %39
62: ; preds = %54, %39
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
br label %24
65: ; preds = %24
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
store i32 0, i32* %3
br label %68
68: ; preds = %65, %16
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"syntax: <encrypted file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"guesses.txt\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = alloca [14 x i8]
%5 = alloca [99 x i8]
%6 = alloca [9 x i8]
%7 = alloca [100 x i8]
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %49
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [99 x i8], [99 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%21 = call i64 @fgets(i8* %16, i32 220, i32* %15)
%22 = icmp eq i64 %21, 0
br i1 %22, label %47, label %23
23: ; preds = %12
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 9
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 13
%26 = getelementptr inbounds [99 x i8], [99 x i8]* %5, i64 0, i64 98
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 8
br label %28
28: ; preds = %23, %43
%29 = call i32 @strncpy(i8* %17, i8* %24, i32 13)
store i8 0, i8* %25
%30 = call i32 @strncpy(i8* %18, i8* %24, i32 98)
store i8 0, i8* %26
%31 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %35, %28
%33 = call i64 @fgets(i8* %20, i32 100, i32* %31)
%34 = icmp eq i64 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %32
%36 = call i32 @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = call i8* @crypt(i8* %20, i8* %17)
%38 = call i32 @strcmp(i8* %18, i8* dereferenceable(1) %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %32
40: ; preds = %35
%41 = call i32 @strncpy(i8* %19, i8* %16, i32 8)
store i8 0, i8* %27
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %43
43: ; preds = %32, %40
%44 = call i32 @fclose(i32* %31)
%45 = call i64 @fgets(i8* %16, i32 220, i32* %15)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %28
47: ; preds = %43, %12
%48 = call i32 @fclose(i32* %15)
br label %49
49: ; preds = %47, %9
ret i32 0
}