#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 */
scalar_t__ authenticate(char *, char *);
char *extract_val(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ print_failure();
int /*<<< orphan*/ print_footer();
int /*<<< orphan*/ print_header();
int /*<<< orphan*/ print_success();
int main(int argc, char **argv) {
  char *username;
  char *password;
  print_header();
  username = extract_val("username");
  if (username == NULL) {
    print_failure();
    print_footer();
    return 0;
  } else {
    password = extract_val("password");
    if (password == NULL) {
      free(username);
      print_failure();
      print_footer();
      return 0;
    }
    if (authenticate(username, password) == 0) {
      print_failure();
    } else {
      print_success();
    }
  }
  print_footer();
  free(username);
  free(password);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <print_header@plt>
lea    0xe6c(%rip),%rdi
call   1080 <extract_val@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <main+0x52>
mov    $0x0,%al
call   1070 <print_failure@plt>
mov    $0x0,%al
call   1060 <print_footer@plt>
movl   $0x0,-0x4(%rbp)
jmp    124f <main+0xdf>
lea    0xe40(%rip),%rdi
call   1080 <extract_val@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1200 <main+0x90>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <print_failure@plt>
mov    $0x0,%al
call   1060 <print_footer@plt>
movl   $0x0,-0x4(%rbp)
jmp    124f <main+0xdf>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <authenticate@plt>
cmp    $0x0,%rax
jne    1223 <main+0xb3>
mov    $0x0,%al
call   1070 <print_failure@plt>
jmp    122a <main+0xba>
mov    $0x0,%al
call   1050 <print_success@plt>
jmp    122f <main+0xbf>
mov    $0x0,%al
call   1060 <print_footer@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <print_header@plt>
lea    0xe7e(%rip),%rdi
call   1080 <extract_val@plt>
test   %rax,%rax
je     11c4 <main+0x54>
mov    %rax,%rbx
lea    0xe73(%rip),%rdi
call   1080 <extract_val@plt>
test   %rax,%rax
je     11bc <main+0x4c>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <authenticate@plt>
test   %rax,%rax
je     11d4 <main+0x64>
xor    %eax,%eax
call   1050 <print_success@plt>
jmp    11db <main+0x6b>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <print_failure@plt>
xor    %eax,%eax
call   1060 <print_footer@plt>
jmp    11f2 <main+0x82>
xor    %eax,%eax
call   1070 <print_failure@plt>
xor    %eax,%eax
call   1060 <print_footer@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"username\00"
@.str.1 = [9 x i8] c"password\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @print_header()
%9 = call i8* @extract_val(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (...) @print_failure()
%14 = call i32 (...) @print_footer()
store i32 0, i32* %3
br label %40
15: ; preds = %2
%16 = call i8* @extract_val(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = call i32 (...) @print_failure()
%23 = call i32 (...) @print_footer()
store i32 0, i32* %3
br label %40
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = call i64 @authenticate(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (...) @print_failure()
br label %33
31: ; preds = %24
%32 = call i32 (...) @print_success()
br label %33
33: ; preds = %31, %29
br label %34
34: ; preds = %33
%35 = call i32 (...) @print_footer()
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %34, %19, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [9 x i8] c"username\00"
@.str.1 = [9 x i8] c"password\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @print_header()
%4 = tail call i8* @extract_val(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (...) @print_failure()
%8 = tail call i32 (...) @print_footer()
br label %27
9: ; preds = %2
%10 = tail call i8* @extract_val(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @free(i8* %4)
%14 = tail call i32 (...) @print_failure()
%15 = tail call i32 (...) @print_footer()
br label %27
16: ; preds = %9
%17 = tail call i64 @authenticate(i8* %4, i8* %10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 (...) @print_failure()
br label %23
21: ; preds = %16
%22 = tail call i32 (...) @print_success()
br label %23
23: ; preds = %19, %21
%24 = tail call i32 (...) @print_footer()
%25 = tail call i32 @free(i8* %4)
%26 = tail call i32 @free(i8* %10)
br label %27
27: ; preds = %23, %12, %6
ret i32 0
}