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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
char *crypt(char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ geteuid();
struct spwd *getspnam(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
char *strerror(int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s user plain_passwd\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (geteuid() != 0) {
    fprintf(stderr, "Error: Cannot possibly work without effective root\n");
    exit(EXIT_FAILURE);
  }
  char *user = argv[1];
  char *plain_passwd = argv[2];
  struct spwd *shadow_entry;
  if ((shadow_entry = getspnam(user)) == NULL) {
    fprintf(stderr, "Error: Unknown user `%s'\n", user);
    exit(EXIT_FAILURE);
  }
  char *enc_passwd;
  if ((enc_passwd = crypt(plain_passwd, shadow_entry->sp_pwdp)) == NULL) {
    fprintf(stderr, "Error: (%d) %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (strcmp(enc_passwd, shadow_entry->sp_pwdp) != 0) {
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
je     11f7 <main+0x77>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <getspnam@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    124f <main+0xcf>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1030 <crypt@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12b7 <main+0x137>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12de <main+0x15e>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11cc <main+0x4c>
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
jne    11dd <main+0x5d>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%r15
mov    %r14,%rdi
call   1080 <getspnam@plt>
test   %rax,%rax
jne    1202 <main+0x82>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11f4 <main+0x74>
mov    (%rbx),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
jmp    11f4 <main+0x74>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    (%rax),%esi
mov    %r15,%rdi
call   1030 <crypt@plt>
test   %rax,%rax
jne    1244 <main+0xc4>
mov    0x2dc5(%rip),%rax
mov    (%rax),%ebx
mov    0x2db4(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xe37(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11f4 <main+0x74>
mov    (%rbx),%esi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f4 <main+0x74>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.spwd = type { i32 }
@.str = [29 x i8] c"Usage: %s user plain_passwd\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [52 x i8] c"Error: Cannot possibly work without effective root\0A\00"
@.str.2 = [26 x i8] c"Error: Unknown user `%s'\0A\00"
@.str.3 = [16 x i8] c"Error: (%d) %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.spwd*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i64 (...) @geteuid()
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
store i8* %33, i8** %7
%34 = load i8*, i8** %6
%35 = call %struct.spwd* @getspnam(i8* %34)
store %struct.spwd* %35, %struct.spwd** %8
%36 = icmp eq %struct.spwd* %35, null
br i1 %36, label %37, label %43
37: ; preds = %27
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %6
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %27
%44 = load i8*, i8** %7
%45 = load %struct.spwd*, %struct.spwd** %8
%46 = getelementptr inbounds %struct.spwd, %struct.spwd* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i8* @crypt(i8* %44, i32 %47)
store i8* %48, i8** %9
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %58
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %52, i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %43
%59 = load i8*, i8** %9
%60 = load %struct.spwd*, %struct.spwd** %8
%61 = getelementptr inbounds %struct.spwd, %struct.spwd* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i64 @strcmp(i8* %59, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %58
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
@.str = [29 x i8] c"Usage: %s user plain_passwd\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [52 x i8] c"Error: Cannot possibly work without effective root\0A\00"
@.str.2 = [26 x i8] c"Error: Unknown user `%s'\0A\00"
@.str.3 = [16 x i8] c"Error: (%d) %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i64 (...) @geteuid()
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call %struct.spwd* @getspnam(i8* %19)
%23 = icmp eq %struct.spwd* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = getelementptr inbounds %struct.spwd, %struct.spwd* %22, i64 0, i32 0
%31 = load i32, i32* %30
%32 = tail call i8* @crypt(i8* %21, i32 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %36, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %29
%42 = load i32, i32* %30
%43 = tail call i64 @strcmp(i8* %32, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
%49 = load i32, i32* @EXIT_SUCCESS
%50 = tail call i32 @exit(i32 %49)
unreachable
}