#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 */
int /*<<< orphan*/ free(char *);
char *hash(char *, int /*<<< orphan*/);
scalar_t__ interesting(char *);
char *malloc(int);
char *part1(char *doorid) {
  unsigned int n = 0;
  char *password = malloc(8 + 1);
  for (unsigned int i = 0; i < 8; i++) {
    for (;;) {
      char *s = hash(doorid, n++);
      if (interesting(s)) {
        password[i] = s[5];
        free(s);
        break;
      }
      free(s);
    }
  }
  password[8] = '\0';
  return password;
}


x86 assembly (clang, -O0):
<part1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jae    11e2 <part1+0xa2>
jmp    1177 <part1+0x37>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
call   1040 <hash@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <interesting@plt>
cmp    $0x0,%rax
je     11c1 <part1+0x81>
mov    -0x28(%rbp),%rax
mov    0x5(%rax),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11cf <part1+0x8f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1177 <part1+0x37>
jmp    11d4 <part1+0x94>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <part1+0x28>
mov    -0x18(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<part1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
xor    %esi,%esi
jmp    118c <part1+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x5(%rbx),%al
mov    %al,(%r14,%r13,1)
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x1,%r13
mov    %r12d,%esi
cmp    $0x8,%r13
je     11dd <part1+0x9d>
lea    0x1(%rsi),%r12d
mov    %r15,%rdi
call   1040 <hash@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <interesting@plt>
test   %rax,%rax
jne    1170 <part1+0x30>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x1(%r12),%ebp
mov    %r15,%rdi
mov    %r12d,%esi
call   1040 <hash@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <interesting@plt>
mov    %ebp,%r12d
test   %rax,%rax
je     11b0 <part1+0x70>
jmp    1170 <part1+0x30>
movb   $0x0,0x8(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @part1(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = call i8* @malloc(i32 9)
store i8* %7, i8** %4
store i32 0, i32* %5
br label %8
8: ; preds = %34, %1
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 8
br i1 %10, label %11, label %37
11: ; preds = %8
br label %12
12: ; preds = %30, %11
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = add i32 %14, 1
store i32 %15, i32* %3
%16 = call i8* @hash(i8* %13, i32 %14)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i64 @interesting(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %12
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 5
%23 = load i8, i8* %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
br label %33
30: ; preds = %12
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
br label %12
33: ; preds = %20
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add i32 %35, 1
store i32 %36, i32* %5
br label %8
37: ; preds = %8
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 8
store i8 0, i8* %39
%40 = load i8*, i8** %4
ret i8* %40
}

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