#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 */

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *hash(char *, int /*<<< orphan*/);
scalar_t__ interesting(char *);
int strlen(char *);
char *part2(char *doorid) {
  unsigned int n = 0;
  char *password = calloc(8 + 1, sizeof(char));
  while (strlen(password) < 8) {
    char *s = hash(doorid, n++);
    if (interesting(s)) {
      char pos = s[5];
      if (pos < '0' || pos > '7') {
        free(s);
        continue;
      }
      int idx = (int)(pos - '0');
      if (password[idx] != '\0') {
        free(s);
        continue;
      }
      password[idx] = s[6];
      free(s);
    }
  }
  return password;
}


x86 assembly (clang, -O0):
<part2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x9,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jge    1232 <part2+0xe2>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
call   1050 <hash@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <interesting@plt>
cmp    $0x0,%rax
je     122d <part2+0xdd>
mov    -0x20(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x30,%eax
jl     11d7 <part2+0x87>
movsbl -0x21(%rbp),%eax
cmp    $0x37,%eax
jle    11e5 <part2+0x95>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1176 <part2+0x26>
movsbl -0x21(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1212 <part2+0xc2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1176 <part2+0x26>
mov    -0x20(%rbp),%rax
mov    0x6(%rax),%dl
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1176 <part2+0x26>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<part2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x9,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jg     11d2 <part2+0x82>
xor    %ebp,%ebp
jmp    1198 <part2+0x48>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    $0x1,%ebp
cmp    $0x8,%eax
jge    11d2 <part2+0x82>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <hash@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <interesting@plt>
test   %rax,%rax
je     1188 <part2+0x38>
movzbl 0x5(%rbx),%eax
lea    -0x38(%rax),%ecx
cmp    $0xf8,%cl
jb     1180 <part2+0x30>
add    $0xffffffd0,%eax
cmpb   $0x0,(%r15,%rax,1)
jne    1180 <part2+0x30>
movzbl 0x6(%rbx),%ecx
mov    %cl,(%r15,%rax,1)
jmp    1180 <part2+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @part2(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%8 = call i8* @calloc(i32 9, i32 1)
store i8* %8, i8** %4
br label %9
9: ; preds = %59, %46, %32, %1
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %60
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = add i32 %15, 1
store i32 %16, i32* %3
%17 = call i8* @hash(i8* %14, i32 %15)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = call i64 @interesting(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %59
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 5
%24 = load i8, i8* %23
store i8 %24, i8* %6
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = icmp slt i32 %26, 48
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp sgt i32 %30, 55
br i1 %31, label %32, label %35
32: ; preds = %28, %21
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
br label %9
35: ; preds = %28
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 48
store i32 %38, i32* %7
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %35
%47 = load i8*, i8** %5
%48 = call i32 @free(i8* %47)
br label %9
49: ; preds = %35
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 6
%52 = load i8, i8* %51
%53 = load i8*, i8** %4
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
%57 = load i8*, i8** %5
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %49, %13
br label %9
60: ; preds = %9
%61 = load i8*, i8** %4
ret i8* %61
}

LLVM IR (-O2):
define i8* @part2(i8* %0) {
%2 = tail call dereferenceable_or_null(9) i8* @calloc(i32 9, i32 1)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp slt i32 %3, 8
br i1 %4, label %5, label %31
5: ; preds = %1, %28
%6 = phi i32 [ %7, %28 ], [ 0, %1 ]
%7 = add i32 %6, 1
%8 = tail call i8* @hash(i8* %0, i32 %6)
%9 = tail call i64 @interesting(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %8, i64 5
%13 = load i8, i8* %12
%14 = add i8 %13, -56
%15 = icmp ult i8 %14, -8
br i1 %15, label %26, label %16
16: ; preds = %11
%17 = zext i8 %13 to i64
%18 = add nuw nsw i64 %17, 4294967248
%19 = and i64 %18, 4294967295
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = getelementptr inbounds i8, i8* %8, i64 6
%25 = load i8, i8* %24
store i8 %25, i8* %20
br label %26
26: ; preds = %16, %11, %23
%27 = tail call i32 @free(i8* %8)
br label %28
28: ; preds = %26, %5
%29 = tail call i32 @strlen(i8* %2)
%30 = icmp slt i32 %29, 8
br i1 %30, label %5, label %31
31: ; preds = %28, %1
ret i8* %2
}