#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 *generate_password(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int);
int strlen(char *);
int main() {
  int passed = 1;
  srand(1337);
  int length = 10;
  char *password = generate_password(length);
  if (strlen(password) == length) {
    printf("\x1B[32mFirst test passed. \n");
  } else {
    passed = 0;
    printf("\x1B[31mFirst test failed. \n");
    printf("Generated password: %s, at length: %i\n", password, length);
  }
  free(password);
  length = 15;
  password = generate_password(length);
  if (strlen(password) == length) {
    printf("\x1B[32mSecond test passed. \n");
  } else {
    passed = 0;
    printf("\x1B[31mSecond test failed. \n");
    printf("Generated password: %s, at length: %i\n", password, length);
  }
  printf("\x1B[0m");
  free(password);
  return !passed;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    $0x539,%edi
call   1060 <srand@plt>
movl   $0xa,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <generate_password@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jne    11a8 <main+0x58>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d2 <main+0x82>
movl   $0x0,-0x8(%rbp)
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xf,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <generate_password@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jne    1213 <main+0xc3>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123d <main+0xed>
movl   $0x0,-0x8(%rbp)
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x539,%edi
call   1070 <srand@plt>
mov    $0xa,%edi
call   1080 <generate_password@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0xa,%eax
jne    119a <main+0x3a>
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    11be <main+0x5e>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xe53(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xf,%edi
call   1080 <generate_password@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0xf,%eax
jne    11ee <main+0x8e>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
jmp    1212 <main+0xb2>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
lea    0xdff(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    $0xf,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\1B[32mFirst test passed. \0A\00"
@.str.1 = [26 x i8] c"\1B[31mFirst test failed. \0A\00"
@.str.2 = [39 x i8] c"Generated password: %s, at length: %i\0A\00"
@.str.3 = [27 x i8] c"\1B[32mSecond test passed. \0A\00"
@.str.4 = [27 x i8] c"\1B[31mSecond test failed. \0A\00"
@.str.5 = [5 x i8] c"\1B[0m\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 1, i32* %2
%5 = call i32 @srand(i32 1337)
store i32 10, i32* %3
%6 = load i32, i32* %3
%7 = call i8* @generate_password(i32 %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = load i32, i32* %3
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %19
14: ; preds = %0
store i32 0, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 %17)
br label %19
19: ; preds = %14, %12
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i32 15, i32* %3
%22 = load i32, i32* %3
%23 = call i8* @generate_password(i32 %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = load i32, i32* %3
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %35
30: ; preds = %19
store i32 0, i32* %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%32 = load i8*, i8** %4
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %33)
br label %35
35: ; preds = %30, %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %2
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
%42 = zext i1 %41 to i32
ret i32 %42
}

LLVM IR (-O2):
@.str.2 = [39 x i8] c"Generated password: %s, at length: %i\0A\00"
@.str.5 = [5 x i8] c"\1B[0m\00"
@str = [25 x i8] c"\1B[31mFirst test failed. \00"
@str.6 = [26 x i8] c"\1B[31mSecond test failed. \00"
@str.7 = [26 x i8] c"\1B[32mSecond test passed. \00"
@str.8 = [25 x i8] c"\1B[32mFirst test passed. \00"
define i32 @main() {
%1 = tail call i32 @srand(i32 1337)
%2 = tail call i8* @generate_password(i32 10)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp eq i32 %3, 10
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
br label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 10)
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ 1, %5 ], [ 0, %7 ]
%12 = tail call i32 @free(i8* %2)
%13 = tail call i8* @generate_password(i32 15)
%14 = tail call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 15
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %21
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %13, i32 15)
br label %21
21: ; preds = %18, %16
%22 = phi i32 [ %11, %16 ], [ 0, %18 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = tail call i32 @free(i8* %13)
%25 = icmp eq i32 %22, 0
%26 = zext i1 %25 to i32
ret i32 %26
}