#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 */
struct termios {
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sha512(char *, char *, char *);
int stdin_prompt(char *, char **);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int passcheck_cb(void *flag, int argc, char **argv, char **colnames) {
  if (argc < 3)
    return 0;
  int showflag = *((int *)flag);
  char *label = argv[0];
  char *salt = argv[1];
  char *hash = argv[2];
  char *pass;
  char passhash[129] = {0};
  int correct = 0;
  struct termios term;
  tcgetattr(STDIN_FILENO, &term);
  term.c_lflag &= ~ECHO;
  while (correct != 1) {
    if (!showflag)
      tcsetattr(STDIN_FILENO, TCSANOW, &term);
    int skip = stdin_prompt(label, &pass);
    if (!showflag) {
      term.c_lflag &= ~ECHO;
      tcsetattr(STDIN_FILENO, TCSANOW, &term);
    }
    if (skip != 0) {
      fprintf(stdout, "\x1B[1;34;49mSkipping.\x1B[0;0;0m\n");
      break;
    }
    sha512(pass, salt, passhash);
    if (strcmp(hash, passhash) != 0) {
      fprintf(stdout, "\x1B[1;31;49mWrong!\x1B[0;0;0m\n");
    } else {
      fprintf(stdout, "\x1B[1;32;49mCorrect!\x1B[0;0;0m\n");
      correct = 1;
    }
    free(pass);
  }
  return 0;
}


x86 assembly (clang, -O0):
<passcheck_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11b0 <passcheck_cb+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1351 <passcheck_cb+0x1d1>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1050 <memset@plt>
movl   $0x0,-0xe4(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    -0xe8(%rbp),%rsi
call   1090 <tcgetattr@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xe8(%rbp),%eax
mov    %eax,-0xe8(%rbp)
cmpl   $0x1,-0xe4(%rbp)
je     134a <passcheck_cb+0x1ca>
cmpl   $0x0,-0x2c(%rbp)
jne    125b <passcheck_cb+0xdb>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    -0xe8(%rbp),%rdx
call   10a0 <tcsetattr@plt>
mov    -0x38(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <stdin_prompt@plt>
mov    %eax,-0xec(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12ae <passcheck_cb+0x12e>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xe8(%rbp),%eax
mov    %eax,-0xe8(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
lea    -0xe8(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmpl   $0x0,-0xec(%rbp)
je     12d5 <passcheck_cb+0x155>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
call   1070 <fprintf@plt>
jmp    134a <passcheck_cb+0x1ca>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
call   1080 <sha512@plt>
mov    -0x48(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     131d <passcheck_cb+0x19d>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    133c <passcheck_cb+0x1bc>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0xe4(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
jmp    1226 <passcheck_cb+0xa6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passcheck_cb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
cmp    $0x3,%esi
jl     1304 <passcheck_cb+0x194>
mov    (%rdi),%r14d
mov    (%rdx),%rax
mov    %rax,0x18(%rsp)
mov    0x8(%rdx),%r13
mov    0x10(%rdx),%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movb   $0x0,0xa0(%rsp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1080 <tcgetattr@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x8(%rsp)
lea    0x20(%rsp),%rbx
mov    0x2dcc(%rip),%r15
test   %r14d,%r14d
je     1230 <passcheck_cb+0xc0>
nopl   0x0(%rax)
mov    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <stdin_prompt@plt>
mov    %eax,%r12d
test   %r12d,%r12d
je     1296 <passcheck_cb+0x126>
jmp    12dd <passcheck_cb+0x16d>
nopl   0x0(%rax)
mov    0x2d91(%rip),%rax
mov    %r13,%rbx
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1090 <tcsetattr@plt>
mov    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <stdin_prompt@plt>
mov    0x2d7b(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    %eax,%r12d
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
lea    0x20(%rsp),%rbx
call   1090 <tcsetattr@plt>
test   %r12d,%r12d
jne    12dd <passcheck_cb+0x16d>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <sha512@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
mov    (%r15),%edi
test   %rax,%rax
je     12ee <passcheck_cb+0x17e>
lea    0xd5d(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
test   %r14d,%r14d
jne    1210 <passcheck_cb+0xa0>
jmp    1230 <passcheck_cb+0xc0>
mov    (%r15),%edi
lea    0xd19(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1304 <passcheck_cb+0x194>
lea    0xd42(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@stdout = global i32 0
@.str = [29 x i8] c"\1B[1;34;49mSkipping.\1B[0;0;0m\0A\00"
@.str.1 = [26 x i8] c"\1B[1;31;49mWrong!\1B[0;0;0m\0A\00"
@.str.2 = [28 x i8] c"\1B[1;32;49mCorrect!\1B[0;0;0m\0A\00"
define i32 @passcheck_cb(i8* %0, i32 %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [129 x i8]
%16 = alloca i32
%17 = alloca %struct.termios
%18 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 0, i32* %5
br label %92
22: ; preds = %4
%23 = load i8*, i8** %6
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
store i32 %25, i32* %10
%26 = load i8**, i8*** %8
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
store i8* %28, i8** %11
%29 = load i8**, i8*** %8
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %12
%32 = load i8**, i8*** %8
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
store i8* %34, i8** %13
%35 = bitcast [129 x i8]* %15 to i8*
store i32 0, i32* %16
%36 = load i32, i32* @STDIN_FILENO
%37 = call i32 @tcgetattr(i32 %36, %struct.termios* %17)
%38 = load i32, i32* @ECHO
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
br label %43
43: ; preds = %88, %22
%44 = load i32, i32* %16
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %91
46: ; preds = %43
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %46
%50 = load i32, i32* @STDIN_FILENO
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 %50, i32 %51, %struct.termios* %17)
br label %53
53: ; preds = %49, %46
%54 = load i8*, i8** %11
%55 = call i32 @stdin_prompt(i8* %54, i8** %14)
store i32 %55, i32* %18
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %53
%59 = load i32, i32* @ECHO
%60 = xor i32 %59, -1
%61 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* @STDIN_FILENO
%65 = load i32, i32* @TCSANOW
%66 = call i32 @tcsetattr(i32 %64, i32 %65, %struct.termios* %17)
br label %67
67: ; preds = %58, %53
%68 = load i32, i32* %18
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load i32, i32* @stdout
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %91
73: ; preds = %67
%74 = load i8*, i8** %14
%75 = load i8*, i8** %12
%76 = getelementptr inbounds [129 x i8], [129 x i8]* %15, i64 0, i64 0
%77 = call i32 @sha512(i8* %74, i8* %75, i8* %76)
%78 = load i8*, i8** %13
%79 = getelementptr inbounds [129 x i8], [129 x i8]* %15, i64 0, i64 0
%80 = call i64 @strcmp(i8* %78, i8* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %73
%83 = load i32, i32* @stdout
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %88
85: ; preds = %73
%86 = load i32, i32* @stdout
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %16
br label %88
88: ; preds = %85, %82
%89 = load i8*, i8** %14
%90 = call i32 @free(i8* %89)
br label %43
91: ; preds = %70, %43
store i32 0, i32* %5
br label %92
92: ; preds = %91, %21
%93 = load i32, i32* %5
ret i32 %93
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@stdout = global i32 0
@.str = [29 x i8] c"\1B[1;34;49mSkipping.\1B[0;0;0m\0A\00"
@.str.1 = [26 x i8] c"\1B[1;31;49mWrong!\1B[0;0;0m\0A\00"
@.str.2 = [28 x i8] c"\1B[1;32;49mCorrect!\1B[0;0;0m\0A\00"
define i32 @passcheck_cb(i8* nocapture %0, i32 %1, i8** nocapture %2, i8** nocapture readnone %3) {
%5 = alloca i8*
%6 = alloca [129 x i8]
%7 = alloca %struct.termios
%8 = icmp slt i32 %1, 3
br i1 %8, label %64, label %9
9: ; preds = %4
%10 = bitcast i8* %0 to i32*
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8*, i8** %2, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %2, i64 2
%16 = load i8*, i8** %15
%17 = bitcast i8** %5 to i8*
%18 = getelementptr inbounds [129 x i8], [129 x i8]* %6, i64 0, i64 0
%19 = bitcast %struct.termios* %7 to i8*
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %7)
%22 = load i32, i32* @ECHO
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %7, i64 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = icmp eq i32 %11, 0
br label %28
28: ; preds = %55, %9
br i1 %27, label %31, label %29
29: ; preds = %28
%30 = call i32 @stdin_prompt(i8* %12, i8** %5)
br label %43
31: ; preds = %28
%32 = load i32, i32* @STDIN_FILENO
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %32, i32 %33, %struct.termios* %7)
%35 = call i32 @stdin_prompt(i8* %12, i8** %5)
%36 = load i32, i32* @ECHO
%37 = xor i32 %36, -1
%38 = load i32, i32* %24
%39 = and i32 %38, %37
store i32 %39, i32* %24
%40 = load i32, i32* @STDIN_FILENO
%41 = load i32, i32* @TCSANOW
%42 = call i32 @tcsetattr(i32 %40, i32 %41, %struct.termios* %7)
br label %43
43: ; preds = %29, %31
%44 = phi i32 [ %35, %31 ], [ %30, %29 ]
%45 = icmp eq i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* @stdout
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %63
49: ; preds = %43
%50 = load i8*, i8** %5
%51 = call i32 @sha512(i8* %50, i8* %14, i8* %18)
%52 = call i64 @strcmp(i8* %16, i8* %18)
%53 = icmp eq i64 %52, 0
%54 = load i32, i32* @stdout
br i1 %53, label %59, label %55
55: ; preds = %49
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%57 = load i8*, i8** %5
%58 = call i32 @free(i8* %57)
br label %28
59: ; preds = %49
%60 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%61 = load i8*, i8** %5
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %59, %46
br label %64
64: ; preds = %4, %63
ret i32 0
}