#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*/ crypt(char const *, int /*<<< orphan*/);
struct spwd *getspnam(char const *);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *);
int strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
int sysauth(const char *username, const char *password) {
  struct spwd *pwd;
  if (getuid() != 0) {
    printf("You need to be root!\n");
    return (1);
  }
  pwd = getspnam(username);
  if (!pwd) {
    printf("User no esxit\n");
    return (1);
  }
  return strcmp(crypt(password, pwd->sp_pwdp), pwd->sp_pwdp);
}


x86 assembly (clang, -O0):
<sysauth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     1189 <sysauth+0x39>
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <sysauth+0x88>
mov    -0x10(%rbp),%rdi
call   1070 <getspnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <sysauth+0x69>
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <sysauth+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1030 <crypt@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1060 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysauth>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     117f <sysauth+0x2f>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1070 <getspnam@plt>
test   %rax,%rax
je     11a9 <sysauth+0x59>
mov    %rax,%rbx
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <crypt@plt>
mov    (%rbx),%esi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strcmp@plt>
lea    0xe50(%rip),%rdi
jmp    116d <sysauth+0x1d>

LLVM IR (-O0):
%struct.spwd = type { i32 }
@.str = [22 x i8] c"You need to be root!\0A\00"
@.str.1 = [15 x i8] c"User no esxit\0A\00"
define i32 @sysauth(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.spwd*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i64 (...) @getuid()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %28
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call %struct.spwd* @getspnam(i8* %12)
store %struct.spwd* %13, %struct.spwd** %6
%14 = load %struct.spwd*, %struct.spwd** %6
%15 = icmp ne %struct.spwd* %14, null
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %28
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load %struct.spwd*, %struct.spwd** %6
%21 = getelementptr inbounds %struct.spwd, %struct.spwd* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @crypt(i8* %19, i32 %22)
%24 = load %struct.spwd*, %struct.spwd** %6
%25 = getelementptr inbounds %struct.spwd, %struct.spwd* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcmp(i32 %23, i32 %26)
store i32 %27, i32* %3
br label %28
28: ; preds = %18, %16, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
@str = [14 x i8] c"User no esxit\00"
@str.2 = [21 x i8] c"You need to be root!\00"
define i32 @sysauth(i8* %0, i8* %1) {
%3 = tail call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.2, i64 0, i64 0))
br label %18
7: ; preds = %2
%8 = tail call %struct.spwd* @getspnam(i8* %0)
%9 = icmp eq %struct.spwd* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %18
12: ; preds = %7
%13 = getelementptr inbounds %struct.spwd, %struct.spwd* %8, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i32 @crypt(i8* %1, i32 %14)
%16 = load i32, i32* %13
%17 = tail call i32 @strcmp(i32 %15, i32 %16)
br label %18
18: ; preds = %12, %10, %5
%19 = phi i32 [ 1, %5 ], [ %17, %12 ], [ 1, %10 ]
ret i32 %19
}