#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*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int login() {
  int accessLevel = 0xff;
  char username[16];
  char password[32];
  printf("Username (max 15 characters): ");
  gets(username);
  printf("Password (max 31 characters): ");
  gets(password);
  if (!strcmp(username, "admin") &&
      !strcmp(password, "{{ create_long_password() }}")) {
    accessLevel = 2;
  } else if (!strcmp(username, "root") &&
             !strcmp(password, "{{ create_long_password() }}")) {
    accessLevel = 0;
  } else if (!strcmp(username, "artist") &&
             !strcmp(password, "my-password-is-secret")) {
    accessLevel = 0x80;
  }
  return accessLevel;
}


x86 assembly (clang, -O0):
<login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0xff,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <gets@plt>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x20(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a7 <login+0x77>
lea    -0x40(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a7 <login+0x77>
movl   $0x2,-0x4(%rbp)
jmp    1228 <login+0xf8>
lea    -0x20(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11e5 <login+0xb5>
lea    -0x40(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11e5 <login+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    1223 <login+0xf3>
lea    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    121e <login+0xee>
lea    -0x40(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    121e <login+0xee>
movl   $0x80,-0x4(%rbp)
jmp    1223 <login+0xf3>
jmp    1228 <login+0xf8>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<login>:
sub    $0x38,%rsp
lea    0xf15(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
call   1040 <gets@plt>
lea    0xf20(%rip),%rdi
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <gets@plt>
mov    $0x696d6461,%eax
xor    (%rsp),%eax
movzwl 0x4(%rsp),%ecx
xor    $0x6e,%ecx
or     %eax,%ecx
jne    1191 <login+0x71>
movdqa 0x10(%rsp),%xmm0
movdqu 0x1d(%rsp),%xmm1
pcmpeqb 0xe8a(%rip),%xmm1
pcmpeqb 0xe92(%rip),%xmm0
pand   %xmm1,%xmm0
pmovmskb %xmm0,%eax
cmp    $0xffff,%eax
je     1227 <login+0x107>
mov    $0x746f6f72,%eax
xor    (%rsp),%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
jne    11cd <login+0xad>
movdqa 0x10(%rsp),%xmm0
movdqu 0x1d(%rsp),%xmm1
pcmpeqb 0xe4a(%rip),%xmm1
pcmpeqb 0xe52(%rip),%xmm0
pand   %xmm1,%xmm0
pmovmskb %xmm0,%eax
cmp    $0xffff,%eax
je     1231 <login+0x111>
mov    $0x69747261,%eax
xor    (%rsp),%eax
mov    $0x747369,%ecx
xor    0x3(%rsp),%ecx
or     %eax,%ecx
mov    $0xff,%eax
je     11ec <login+0xcc>
add    $0x38,%rsp
ret
movdqa 0x10(%rsp),%xmm0
movdqu 0x16(%rsp),%xmm1
pcmpeqb 0xe20(%rip),%xmm1
pcmpeqb 0xe28(%rip),%xmm0
pand   %xmm1,%xmm0
pmovmskb %xmm0,%eax
cmp    $0xffff,%eax
mov    $0x80,%ecx
mov    $0xff,%eax
cmove  %ecx,%eax
add    $0x38,%rsp
ret
mov    $0x2,%eax
add    $0x38,%rsp
ret
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Username (max 15 characters): \00"
@.str.1 = [31 x i8] c"Password (max 31 characters): \00"
@.str.2 = [6 x i8] c"admin\00"
@.str.3 = [29 x i8] c"{{ create_long_password() }}\00"
@.str.4 = [5 x i8] c"root\00"
@.str.5 = [7 x i8] c"artist\00"
@.str.6 = [22 x i8] c"my-password-is-secret\00"
define i32 @login() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [32 x i8]
store i32 255, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
store i32 2, i32* %1
br label %38
18: ; preds = %13, %0
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i32 0, i32* %1
br label %37
27: ; preds = %22, %18
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
store i32 128, i32* %1
br label %36
36: ; preds = %35, %31, %27
br label %37
37: ; preds = %36, %26
br label %38
38: ; preds = %37, %17
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [31 x i8] c"Username (max 15 characters): \00"
@.str.1 = [31 x i8] c"Password (max 31 characters): \00"
@.str.2 = [6 x i8] c"admin\00"
@.str.3 = [29 x i8] c"{{ create_long_password() }}\00"
@.str.4 = [5 x i8] c"root\00"
@.str.5 = [7 x i8] c"artist\00"
@.str.6 = [22 x i8] c"my-password-is-secret\00"
define i32 @login() {
%1 = alloca [16 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 @bcmp(i8* dereferenceable(6) %3, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @bcmp(i8* dereferenceable(29) %4, i8* dereferenceable(29) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 29)
%13 = icmp eq i32 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %11, %0
%15 = call i32 @bcmp(i8* dereferenceable(5) %3, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @bcmp(i8* dereferenceable(29) %4, i8* dereferenceable(29) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 29)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %17, %14
%21 = call i32 @bcmp(i8* dereferenceable(7) %3, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 7)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = call i32 @bcmp(i8* dereferenceable(22) %4, i8* dereferenceable(22) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i64 22)
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i32 128, i32 255
br label %27
27: ; preds = %23, %17, %11, %20
%28 = phi i32 [ 255, %20 ], [ 2, %11 ], [ 0, %17 ], [ %26, %23 ]
ret i32 %28
}