#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 spwd {
  int /*<<< orphan*/ sp_pwdp;
};
struct passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
char *crypt(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct passwd *getpwnam(char *);
struct spwd *getspnam(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int main(int ac, char **av, char **ev) {
  char username[64];
  char password[64];
  char line[512];
  char format[20];
  struct passwd *pwp;
  struct spwd *spwd;
  fgets(line, 512, stdin);
  sprintf(format, "LOGIN:%%%ds %%%ds", 64 - 1, 64 - 1);
  sscanf(line, format, username, password);
  pwp = getpwnam(username);
  if (pwp == (struct passwd *)NULL) {
    fprintf(stdout, "FAILED: [%s] does not exists.\n", username);
    exit(1);
  }
  spwd = getspnam(pwp->pw_name);
  if (spwd == (struct spwd *)NULL) {
    fprintf(stdout,
            "FAILED: unable to get (shadow) password for '%s', because '%s'\n",
            username, strerror(errno));
    exit(1);
  } else {
    char *gen = crypt(password, spwd->sp_pwdp);
    if (gen == (char *)NULL) {
      fprintf(stdout, "FAILED: crypt failed with: '%s'\n", strerror(errno));
      exit(1);
    }
    if (strcmp(spwd->sp_pwdp, gen) == 0) {
      fprintf(stdout, "OK:\n");
      exit(0);
    } else {
      fprintf(stdout, "FAILED: Password did not match.\n");
      exit(1);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x2a0(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    -0x2c0(%rbp),%rdi
lea    0xe1b(%rip),%rsi
mov    $0x3f,%ecx
mov    %ecx,%edx
call   10a0 <sprintf@plt>
lea    -0x2a0(%rbp),%rdi
lea    -0x2c0(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
call   1080 <sscanf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x2c8(%rbp)
cmpq   $0x0,-0x2c8(%rbp)
jne    1252 <main+0xb2>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c8(%rbp),%rax
mov    (%rax),%edi
call   1090 <getspnam@plt>
mov    %rax,-0x2d0(%rbp)
cmpq   $0x0,-0x2d0(%rbp)
jne    12c5 <main+0x125>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2e4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x2e0(%rbp)
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2e4(%rbp),%edi
mov    -0x2e0(%rbp),%rdx
mov    %rax,%rcx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x2d0(%rbp),%rax
mov    (%rax),%esi
call   1030 <crypt@plt>
mov    %rax,-0x2d8(%rbp)
cmpq   $0x0,-0x2d8(%rbp)
jne    132d <main+0x18d>
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2e8(%rbp)
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2e8(%rbp),%edi
mov    %rax,%rdx
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2d0(%rbp),%rax
mov    (%rax),%edi
mov    -0x2d8(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    136a <main+0x1ca>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x2a0,%rsp
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1040 <fgets@plt>
lea    0xe2f(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x3f,%edx
mov    $0x3f,%ecx
call   10a0 <sprintf@plt>
lea    0x20(%rsp),%rbx
lea    0x60(%rsp),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <sscanf@plt>
mov    %rbx,%rdi
call   1060 <getpwnam@plt>
test   %rax,%rax
jne    1222 <main+0x82>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
lea    0x20(%rsp),%rdx
jmp    129e <main+0xfe>
mov    (%rax),%edi
call   1090 <getspnam@plt>
test   %rax,%rax
jne    1267 <main+0xc7>
mov    0x2d9b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xde5(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0x60(%rsp),%rdi
call   1030 <crypt@plt>
test   %rax,%rax
jne    12af <main+0x10f>
mov    0x2d4e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdd8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    (%rbx),%edi
mov    %rax,%rsi
call   1050 <strcmp@plt>
mov    0x2d10(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
jne    12dc <main+0x13c>
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
%struct.spwd = type { i32 }
@stdin = global i32 0
@.str = [18 x i8] c"LOGIN:%%%ds %%%ds\00"
@stdout = global i32 0
@.str.1 = [31 x i8] c"FAILED: [%s] does not exists.\0A\00"
@.str.2 = [64 x i8] c"FAILED: unable to get (shadow) password for '%s', because '%s'\0A\00"
@errno = global i32 0
@.str.3 = [33 x i8] c"FAILED: crypt failed with: '%s'\0A\00"
@.str.4 = [5 x i8] c"OK:\0A\00"
@.str.5 = [33 x i8] c"FAILED: Password did not match.\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
%10 = alloca [512 x i8]
%11 = alloca [20 x i8]
%12 = alloca %struct.passwd*
%13 = alloca %struct.spwd*
%14 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 512, i32 %16)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%19 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 63, i32 63)
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%24 = call i32 @sscanf(i8* %20, i8* %21, i8* %22, i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%26 = call %struct.passwd* @getpwnam(i8* %25)
store %struct.passwd* %26, %struct.passwd** %12
%27 = load %struct.passwd*, %struct.passwd** %12
%28 = icmp eq %struct.passwd* %27, null
br i1 %28, label %29, label %34
29: ; preds = %3
%30 = load i32, i32* @stdout
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %3
%35 = load %struct.passwd*, %struct.passwd** %12
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call %struct.spwd* @getspnam(i32 %37)
store %struct.spwd* %38, %struct.spwd** %13
%39 = load %struct.spwd*, %struct.spwd** %13
%40 = icmp eq %struct.spwd* %39, null
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load i32, i32* @stdout
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %34
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%50 = load %struct.spwd*, %struct.spwd** %13
%51 = getelementptr inbounds %struct.spwd, %struct.spwd* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i8* @crypt(i8* %49, i32 %52)
store i8* %53, i8** %14
%54 = load i8*, i8** %14
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %62
56: ; preds = %48
%57 = load i32, i32* @stdout
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %59)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %48
%63 = load %struct.spwd*, %struct.spwd** %13
%64 = getelementptr inbounds %struct.spwd, %struct.spwd* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = load i8*, i8** %14
%67 = call i64 @strcmp(i32 %65, i8* %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %62
%70 = load i32, i32* @stdout
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %62
%74 = load i32, i32* @stdout
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
%struct.spwd = type { i32 }
@stdin = global i32 0
@.str = [18 x i8] c"LOGIN:%%%ds %%%ds\00"
@stdout = global i32 0
@.str.1 = [31 x i8] c"FAILED: [%s] does not exists.\0A\00"
@.str.2 = [64 x i8] c"FAILED: unable to get (shadow) password for '%s', because '%s'\0A\00"
@errno = global i32 0
@.str.3 = [33 x i8] c"FAILED: crypt failed with: '%s'\0A\00"
@.str.4 = [5 x i8] c"OK:\0A\00"
@.str.5 = [33 x i8] c"FAILED: Password did not match.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca [512 x i8]
%7 = alloca [20 x i8]
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %10, i32 512, i32 %12)
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 63, i32 63)
%15 = call i32 @sscanf(i8* %10, i8* %11, i8* %8, i8* %9)
%16 = call %struct.passwd* @getpwnam(i8* %8)
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %3
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call %struct.spwd* @getspnam(i32 %24)
%26 = icmp eq %struct.spwd* %25, null
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* @stdout
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %22
%34 = getelementptr inbounds %struct.spwd, %struct.spwd* %25, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i8* @crypt(i8* %9, i32 %35)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i32, i32* @stdout
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %33
%45 = load i32, i32* %34
%46 = call i64 @strcmp(i32 %45, i8* %36)
%47 = icmp eq i64 %46, 0
%48 = load i32, i32* @stdout
br i1 %47, label %49, label %52
49: ; preds = %44
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %44
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
}