#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 */
typedef int /*<<< orphan*/ uid_t;
struct passwd {
  int /*<<< orphan*/ pw_gid;
  int /*<<< orphan*/ pw_uid;
};
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ _SC_GETPW_R_SIZE_MAX;
scalar_t__ getpwnam_r(char const *, struct passwd *, char *, long const,
                      struct passwd **);
long sysconf(int /*<<< orphan*/);
int name_to_uid(char const *name, uid_t *login_uid, gid_t *login_gid) {
  if (NULL == name || NULL == login_uid || NULL == login_gid)
    return -1;
  long const buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (buflen == -1)
    return -1;
  char buf[buflen];
  struct passwd pwbuf, *pwbufp;
  if (0 != getpwnam_r(name, &pwbuf, buf, buflen, &pwbufp) || !pwbufp)
    return -1;
  *login_uid = pwbufp->pw_uid;
  *login_gid = pwbufp->pw_gid;
  return 0;
}


x86 assembly (clang, -O0):
<name_to_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1158 <name_to_uid+0x38>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1158 <name_to_uid+0x38>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1164 <name_to_uid+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <name_to_uid+0xff>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    118d <name_to_uid+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <name_to_uid+0xff>
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rcx
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%r8
call   1030 <getpwnam_r@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11de <name_to_uid+0xbe>
cmpq   $0x0,-0x48(%rbp)
jne    11f1 <name_to_uid+0xd1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1218 <name_to_uid+0xf8>
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<name_to_uid>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%r12d
test   %rdi,%rdi
je     11b2 <name_to_uid+0x92>
mov    %rsi,%r15
test   %rsi,%rsi
je     11b2 <name_to_uid+0x92>
mov    %rdx,%r14
test   %rdx,%rdx
je     11b2 <name_to_uid+0x92>
mov    %rdi,%rbx
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
je     11b2 <name_to_uid+0x92>
mov    %rsp,%r13
mov    %rsp,%rdx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,%rsp
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    %rbx,%rdi
mov    %rax,%rcx
call   1030 <getpwnam_r@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    11af <name_to_uid+0x8f>
mov    -0x30(%rbp),%rax
test   %rax,%rax
je     11af <name_to_uid+0x8f>
mov    0x4(%rax),%ecx
mov    %ecx,(%r15)
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %r12d,%r12d
mov    %r13,%rsp
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
@_SC_GETPW_R_SIZE_MAX = global i32 0
define i32 @name_to_uid(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.passwd
%12 = alloca %struct.passwd*
%13 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%14 = load i8*, i8** %5
%15 = icmp eq i8* null, %14
br i1 %15, label %22, label %16
16: ; preds = %3
%17 = load i32*, i32** %6
%18 = icmp eq i32* null, %17
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32*, i32** %7
%21 = icmp eq i32* null, %20
br i1 %21, label %22, label %23
22: ; preds = %19, %16, %3
store i32 -1, i32* %4
br label %52
23: ; preds = %19
%24 = load i32, i32* @_SC_GETPW_R_SIZE_MAX
%25 = call i64 @sysconf(i32 %24)
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %4
br label %52
29: ; preds = %23
%30 = load i64, i64* %8
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %9
%32 = alloca i8, i64 %30
store i64 %30, i64* %10
%33 = load i8*, i8** %5
%34 = load i64, i64* %8
%35 = call i64 @getpwnam_r(i8* %33, %struct.passwd* %11, i8* %32, i64 %34, %struct.passwd** %12)
%36 = icmp ne i64 0, %35
br i1 %36, label %40, label %37
37: ; preds = %29
%38 = load %struct.passwd*, %struct.passwd** %12
%39 = icmp ne %struct.passwd* %38, null
br i1 %39, label %41, label %40
40: ; preds = %37, %29
store i32 -1, i32* %4
store i32 1, i32* %13
br label %50
41: ; preds = %37
%42 = load %struct.passwd*, %struct.passwd** %12
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 1
%44 = load i32, i32* %43
%45 = load i32*, i32** %6
store i32 %44, i32* %45
%46 = load %struct.passwd*, %struct.passwd** %12
%47 = getelementptr inbounds %struct.passwd, %struct.passwd* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = load i32*, i32** %7
store i32 %48, i32* %49
store i32 0, i32* %4
store i32 1, i32* %13
br label %50
50: ; preds = %41, %40
%51 = load i8*, i8** %9
br label %52
52: ; preds = %50, %28, %22
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@_SC_GETPW_R_SIZE_MAX = global i32 0
define i32 @name_to_uid(i8* %0, i32* writeonly %1, i32* writeonly %2) {
%4 = alloca %struct.passwd
%5 = alloca %struct.passwd*
%6 = icmp eq i8* %0, null
%7 = icmp eq i32* %1, null
%8 = or i1 %6, %7
%9 = icmp eq i32* %2, null
%10 = or i1 %8, %9
br i1 %10, label %32, label %11
11: ; preds = %3
%12 = load i32, i32* @_SC_GETPW_R_SIZE_MAX
%13 = tail call i64 @sysconf(i32 %12)
%14 = icmp eq i64 %13, -1
br i1 %14, label %32, label %15
15: ; preds = %11
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %13
%18 = bitcast %struct.passwd* %4 to i8*
%19 = bitcast %struct.passwd** %5 to i8*
%20 = call i64 @getpwnam_r(i8* %0, %struct.passwd* %4, i8* %17, i64 %13, %struct.passwd** %5)
%21 = icmp eq i64 %20, 0
%22 = load %struct.passwd*, %struct.passwd** %5
%23 = icmp ne %struct.passwd* %22, null
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 1
%27 = load i32, i32* %26
store i32 %27, i32* %1
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i64 0, i32 0
%29 = load i32, i32* %28
store i32 %29, i32* %2
br label %30
30: ; preds = %15, %25
%31 = phi i32 [ 0, %25 ], [ -1, %15 ]
br label %32
32: ; preds = %30, %11, %3
%33 = phi i32 [ -1, %3 ], [ %31, %30 ], [ -1, %11 ]
ret i32 %33
}