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

/* Variables and functions */
char *crypt(char const *, char *);
scalar_t__ errno;
struct spwd *getspnam(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ weprintf(char *, ...);
int pw_check(const struct passwd *pw, const char *pass) {
  char *cryptpass, *p;
  struct spwd *spw;
  p = pw->pw_passwd;
  if (p[0] == '!' || p[0] == '*') {
    weprintf("denied\n");
    return -1;
  }
  if (pw->pw_passwd[0] == '\0') {
    if (pass[0] == '\0')
      return 1;
    weprintf("incorrect password\n");
    return 0;
  }
  if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '\0') {
    errno = 0;
    spw = getspnam(pw->pw_name);
    if (!spw) {
      if (errno)
        weprintf("getspnam: %s:", pw->pw_name);
      else
        weprintf("who are you?\n");
      return -1;
    }
    p = spw->sp_pwdp;
    if (p[0] == '!' || p[0] == '*') {
      weprintf("denied\n");
      return -1;
    }
  }
  cryptpass = crypt(pass, p);
  if (!cryptpass) {
    weprintf("crypt:");
    return -1;
  }
  if (strcmp(cryptpass, p) != 0) {
    weprintf("incorrect password\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pw_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
je     117b <pw_check+0x3b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    1195 <pw_check+0x55>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11de <pw_check+0x9e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c4 <pw_check+0x84>
movl   $0x1,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
jne    12bd <pw_check+0x17d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    12bd <pw_check+0x17d>
mov    0x2dd4(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1060 <getspnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1273 <pw_check+0x133>
mov    0x2dab(%rip),%rax
cmpq   $0x0,(%rax)
je     1259 <pw_check+0x119>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
jmp    1267 <pw_check+0x127>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
je     129e <pw_check+0x15e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    12b8 <pw_check+0x178>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
jmp    12bd <pw_check+0x17d>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <crypt@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12f3 <pw_check+0x1b3>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1324 <pw_check+0x1e4>
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1050 <weprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    132b <pw_check+0x1eb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pw_check>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    (%rdi),%r15
mov    (%r15),%al
cmp    $0x29,%al
jg     115c <pw_check+0x1c>
test   %al,%al
je     116d <pw_check+0x2d>
cmp    $0x21,%al
je     1164 <pw_check+0x24>
jmp    1181 <pw_check+0x41>
cmp    $0x78,%al
je     117a <pw_check+0x3a>
cmp    $0x2a,%al
jne    1181 <pw_check+0x41>
lea    0xe95(%rip),%rdi
jmp    11ba <pw_check+0x7a>
cmpb   $0x0,(%r14)
jne    11a1 <pw_check+0x61>
mov    $0x1,%ebx
jmp    11c6 <pw_check+0x86>
cmpb   $0x0,0x1(%r15)
je     11ce <pw_check+0x8e>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <crypt@plt>
test   %rax,%rax
je     11b3 <pw_check+0x73>
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1173 <pw_check+0x33>
lea    0xe60(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <weprintf@plt>
jmp    11c6 <pw_check+0x86>
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <weprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rdi,%rbx
mov    0x2e08(%rip),%r15
movq   $0x0,(%r15)
mov    0x8(%rdi),%edi
call   1060 <getspnam@plt>
test   %rax,%rax
je     11ff <pw_check+0xbf>
mov    (%rax),%r15
mov    (%r15),%al
cmp    $0x2a,%al
jne    1156 <pw_check+0x16>
jmp    1164 <pw_check+0x24>
cmpq   $0x0,(%r15)
je     1218 <pw_check+0xd8>
mov    0x8(%rbx),%esi
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1050 <weprintf@plt>
jmp    11c1 <pw_check+0x81>
lea    0xe0b(%rip),%rdi
jmp    11ba <pw_check+0x7a>

LLVM IR (-O0):
%struct.passwd = type { i8*, i32 }
%struct.spwd = type { i8* }
@.str = [8 x i8] c"denied\0A\00"
@.str.1 = [20 x i8] c"incorrect password\0A\00"
@errno = global i64 0
@.str.2 = [14 x i8] c"getspnam: %s:\00"
@.str.3 = [14 x i8] c"who are you?\0A\00"
@.str.4 = [7 x i8] c"crypt:\00"
define i32 @pw_check(%struct.passwd* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.passwd*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.spwd*
store %struct.passwd* %0, %struct.passwd** %4
store i8* %1, i8** %5
%9 = load %struct.passwd*, %struct.passwd** %4
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 0
%11 = load i8*, i8** %10
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 33
br i1 %16, label %23, label %17
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 42
br i1 %22, label %23, label %25
23: ; preds = %17, %2
%24 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %110
25: ; preds = %17
%26 = load %struct.passwd*, %struct.passwd** %4
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 1, i32* %3
br label %110
40: ; preds = %33
%41 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %110
42: ; preds = %25
%43 = load %struct.passwd*, %struct.passwd** %4
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 120
br i1 %49, label %50, label %94
50: ; preds = %42
%51 = load %struct.passwd*, %struct.passwd** %4
%52 = getelementptr inbounds %struct.passwd, %struct.passwd* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %94
58: ; preds = %50
store i64 0, i64* @errno
%59 = load %struct.passwd*, %struct.passwd** %4
%60 = getelementptr inbounds %struct.passwd, %struct.passwd* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = call %struct.spwd* @getspnam(i32 %61)
store %struct.spwd* %62, %struct.spwd** %8
%63 = load %struct.spwd*, %struct.spwd** %8
%64 = icmp ne %struct.spwd* %63, null
br i1 %64, label %76, label %65
65: ; preds = %58
%66 = load i64, i64* @errno
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %65
%69 = load %struct.passwd*, %struct.passwd** %4
%70 = getelementptr inbounds %struct.passwd, %struct.passwd* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %71)
br label %75
73: ; preds = %65
%74 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %73, %68
store i32 -1, i32* %3
br label %110
76: ; preds = %58
%77 = load %struct.spwd*, %struct.spwd** %8
%78 = getelementptr inbounds %struct.spwd, %struct.spwd* %77, i32 0, i32 0
%79 = load i8*, i8** %78
store i8* %79, i8** %7
%80 = load i8*, i8** %7
%81 = getelementptr inbounds i8, i8* %80, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 33
br i1 %84, label %91, label %85
85: ; preds = %76
%86 = load i8*, i8** %7
%87 = getelementptr inbounds i8, i8* %86, i64 0
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp eq i32 %89, 42
br i1 %90, label %91, label %93
91: ; preds = %85, %76
%92 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %110
93: ; preds = %85
br label %94
94: ; preds = %93, %50, %42
%95 = load i8*, i8** %5
%96 = load i8*, i8** %7
%97 = call i8* @crypt(i8* %95, i8* %96)
store i8* %97, i8** %6
%98 = load i8*, i8** %6
%99 = icmp ne i8* %98, null
br i1 %99, label %102, label %100
100: ; preds = %94
%101 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %110
102: ; preds = %94
%103 = load i8*, i8** %6
%104 = load i8*, i8** %7
%105 = call i64 @strcmp(i8* %103, i8* %104)
%106 = icmp ne i64 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %102
%108 = call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %110
109: ; preds = %102
store i32 1, i32* %3
br label %110
110: ; preds = %109, %107, %100, %91, %75, %40, %39, %23
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i32 }
%struct.spwd = type { i8* }
@.str = [8 x i8] c"denied\0A\00"
@.str.1 = [20 x i8] c"incorrect password\0A\00"
@errno = global i64 0
@.str.2 = [14 x i8] c"getspnam: %s:\00"
@.str.3 = [14 x i8] c"who are you?\0A\00"
@.str.4 = [7 x i8] c"crypt:\00"
define i32 @pw_check(%struct.passwd* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
switch i8 %5, label %36 [
i8 33, label %6
i8 42, label %6
i8 0, label %8
i8 120, label %13
]
6: ; preds = %2, %2
%7 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %47
8: ; preds = %2
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %47, label %11
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %47
13: ; preds = %2
%14 = getelementptr inbounds i8, i8* %4, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %13
store i64 0, i64* @errno
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%19 = load i32, i32* %18
%20 = tail call %struct.spwd* @getspnam(i32 %19)
%21 = icmp eq %struct.spwd* %20, null
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %18
%27 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %47
28: ; preds = %22
%29 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %47
30: ; preds = %17
%31 = getelementptr inbounds %struct.spwd, %struct.spwd* %20, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = load i8, i8* %32
switch i8 %33, label %36 [
i8 33, label %34
i8 42, label %34
]
34: ; preds = %30, %30
%35 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %47
36: ; preds = %30, %2, %13
%37 = phi i8* [ %4, %13 ], [ %4, %2 ], [ %32, %30 ]
%38 = tail call i8* @crypt(i8* %1, i8* %37)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %47
42: ; preds = %36
%43 = tail call i64 @strcmp(i8* %38, i8* %37)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = tail call i32 (i8*, ...) @weprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %42, %25, %28, %8, %45, %40, %34, %11, %6
%48 = phi i32 [ -1, %6 ], [ 0, %11 ], [ -1, %34 ], [ 0, %45 ], [ -1, %40 ], [ 1, %8 ], [ -1, %28 ], [ -1, %25 ], [ 1, %42 ]
ret i32 %48
}