#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int verify_password(char *, char *);
int check_password2(char *prompt, char *username) {
  char buffer[128];
  if (verify_password(username, 0) != 0)
    return 1;
  memset(buffer, 0, 128);
  printf("%s", prompt);
  fflush(0);
  if (!fgets(buffer, 128, stdin))
    return 0;
  char *nl = strchr(buffer, '\n');
  if (nl)
    *nl = 0;
  int r = verify_password(username, buffer);
  switch (r) {
  case 4:
    fprintf(stderr, "shadow file format error!\n");
  case 1:
  case 2:
  case 0:
    return 1;
  case 3:
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_password2>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <verify_password@plt>
cmp    $0x0,%eax
je     11a5 <check_password2+0x35>
movl   $0x1,-0x4(%rbp)
jmp    12ba <check_password2+0x14a>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11fe <check_password2+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    12ba <check_password2+0x14a>
lea    -0xa0(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     122e <check_password2+0xbe>
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <verify_password@plt>
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    %eax,-0xb0(%rbp)
sub    $0x3,%eax
jb     129b <check_password2+0x12b>
jmp    125e <check_password2+0xee>
mov    -0xb0(%rbp),%eax
sub    $0x3,%eax
je     12a7 <check_password2+0x137>
jmp    1272 <check_password2+0x102>
mov    -0xb0(%rbp),%eax
sub    $0x4,%eax
jne    12b3 <check_password2+0x143>
jmp    1286 <check_password2+0x116>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xd6d(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ba <check_password2+0x14a>
movl   $0x0,-0x4(%rbp)
jmp    12ba <check_password2+0x14a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_password2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
xor    %esi,%esi
call   1030 <verify_password@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    1221 <check_password2+0xb1>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe4c(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
test   %eax,%eax
je     121e <check_password2+0xae>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f2 <check_password2+0x82>
movb   $0x0,(%rax)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <verify_password@plt>
cmp    $0x3,%eax
je     121e <check_password2+0xae>
cmp    $0x4,%eax
jne    1221 <check_password2+0xb1>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1221 <check_password2+0xb1>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"shadow file format error!\0A\00"
define i32 @check_password2(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [128 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @verify_password(i8* %9, i8* null)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %42
13: ; preds = %2
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 128)
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @fflush(i32 0)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32 @fgets(i8* %19, i32 128, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %13
store i32 0, i32* %3
br label %42
24: ; preds = %13
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i8*, i8** %7
store i8 0, i8* %30
br label %31
31: ; preds = %29, %24
%32 = load i8*, i8** %5
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%34 = call i32 @verify_password(i8* %32, i8* %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
switch i32 %35, label %41 [
i32 4, label %36
i32 1, label %39
i32 2, label %39
i32 0, label %39
i32 3, label %40
]
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %31, %31, %31, %36
store i32 1, i32* %3
br label %42
40: ; preds = %31
store i32 0, i32* %3
br label %42
41: ; preds = %31
store i32 1, i32* %3
br label %42
42: ; preds = %41, %40, %39, %23, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"shadow file format error!\0A\00"
define i32 @check_password2(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @verify_password(i8* %1, i8* null)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %2
%8 = call i32 @memset(i8* %4, i32 0, i32 128)
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @fflush(i32 0)
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %4, i32 128, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %7
%15 = call i8* @strchr(i8* %4, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8 0, i8* %15
br label %18
18: ; preds = %17, %14
%19 = call i32 @verify_password(i8* %1, i8* %4)
switch i32 %19, label %24 [
i32 4, label %20
i32 3, label %23
]
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %20, %18, %7, %2
%25 = phi i32 [ 1, %2 ], [ 0, %7 ], [ 0, %23 ], [ 1, %20 ], [ 1, %18 ]
ret i32 %25
}