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

/* Variables and functions */
scalar_t__ crypt(char *, int /*<<< orphan*/);
struct passwd *getpwnam(char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int passwd_auth(char *user, char *passwd) {
  struct passwd *pwd;
  pwd = getpwnam(user);
  if (pwd == NULL) {
    return 0;
  } else {
    if (strcmp(pwd->pw_passwd, (char *)crypt(passwd, pwd->pw_passwd))) {
      return 2;
    } else {
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<passwd_auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <passwd_auth+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <passwd_auth+0x74>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1030 <crypt@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     119d <passwd_auth+0x6d>
movl   $0x2,-0x4(%rbp)
jmp    11a4 <passwd_auth+0x74>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passwd_auth>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1164 <passwd_auth+0x34>
mov    (%rax),%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <crypt@plt>
mov    %ebp,%edi
mov    %rax,%rsi
call   1040 <strcmp@plt>
cmp    $0x1,%rax
mov    $0x2,%eax
sbb    $0x0,%eax
jmp    1166 <passwd_auth+0x36>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
define i32 @passwd_auth(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.passwd*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call %struct.passwd* @getpwnam(i8* %7)
store %struct.passwd* %8, %struct.passwd** %6
%9 = load %struct.passwd*, %struct.passwd** %6
%10 = icmp eq %struct.passwd* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %26
12: ; preds = %2
%13 = load %struct.passwd*, %struct.passwd** %6
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %5
%17 = load %struct.passwd*, %struct.passwd** %6
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @crypt(i8* %16, i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = call i64 @strcmp(i32 %15, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 2, i32* %3
br label %26
25: ; preds = %12
store i32 1, i32* %3
br label %26
26: ; preds = %25, %24, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define i32 @passwd_auth(i8* nocapture %0, i8* %1) {
%3 = tail call %struct.passwd* @getpwnam(i8* %0)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i64 @crypt(i8* %1, i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i64 @strcmp(i32 %7, i8* %9)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 1, i32 2
br label %13
13: ; preds = %5, %2
%14 = phi i32 [ 0, %2 ], [ %12, %5 ]
ret i32 %14
}