#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;
};

/* Variables and functions */
int /*<<< orphan*/ crypt(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct spwd *getspnam(char *);
int /*<<< orphan*/ stderr;
int strcmp(char *, int /*<<< orphan*/);
int auth(char *login, char *key) {
  struct spwd *sp = getspnam(login);
  if (sp == NULL || sp->sp_pwdp == NULL) {
    fprintf(stderr, "Wrong user!\n");
    return 0;
  }
  char *shadow = sp->sp_pwdp;
  int rv = strcmp(shadow, crypt(key, shadow));
  if (rv == 0)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getspnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1176 <auth+0x36>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1197 <auth+0x57>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <auth+0xa2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <crypt@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11db <auth+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <auth+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auth>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <getspnam@plt>
test   %rax,%rax
je     1179 <auth+0x39>
mov    (%rax),%rbx
test   %rbx,%rbx
je     1179 <auth+0x39>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <crypt@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    1190 <auth+0x50>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.spwd = type { i8* }
@stderr = global i32 0
@.str = [13 x i8] c"Wrong user!\0A\00"
define i32 @auth(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.spwd*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call %struct.spwd* @getspnam(i8* %9)
store %struct.spwd* %10, %struct.spwd** %6
%11 = load %struct.spwd*, %struct.spwd** %6
%12 = icmp eq %struct.spwd* %11, null
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load %struct.spwd*, %struct.spwd** %6
%15 = getelementptr inbounds %struct.spwd, %struct.spwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13, %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %34
21: ; preds = %13
%22 = load %struct.spwd*, %struct.spwd** %6
%23 = getelementptr inbounds %struct.spwd, %struct.spwd* %22, i32 0, i32 0
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8*, i8** %5
%27 = load i8*, i8** %7
%28 = call i32 @crypt(i8* %26, i8* %27)
%29 = call i32 @strcmp(i8* %25, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %21
store i32 1, i32* %3
br label %34
33: ; preds = %21
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %18
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.spwd = type { i8* }
@stderr = global i32 0
@.str = [13 x i8] c"Wrong user!\0A\00"
define i32 @auth(i8* %0, i8* %1) {
%3 = tail call %struct.spwd* @getspnam(i8* %0)
%4 = icmp eq %struct.spwd* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.spwd, %struct.spwd* %3, i64 0, i32 0
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %5, %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %17
12: ; preds = %5
%13 = tail call i32 @crypt(i8* %1, i8* %7)
%14 = tail call i32 @strcmp(i8* %7, i32 %13)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %12, %9
%18 = phi i32 [ 0, %9 ], [ %16, %12 ]
ret i32 %18
}