#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 */
scalar_t__ errno;
struct passwd *getpwnam(char const *);
int get_uid_gid(const char *username, uid_t *uid, gid_t *gid) {
  struct passwd *p;
  errno = 0;
  p = getpwnam(username);
  if (p == NULL)
    return -1;
  *uid = p->pw_uid;
  *gid = p->pw_gid;
  return 0;
}


x86 assembly (clang, -O0):
<get_uid_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1156 <get_uid_gid+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1176 <get_uid_gid+0x66>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uid_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2ebf(%rip),%rax
movq   $0x0,(%rax)
call   1030 <getpwnam@plt>
test   %rax,%rax
je     1140 <get_uid_gid+0x30>
mov    0x4(%rax),%ecx
mov    %ecx,(%rbx)
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    1145 <get_uid_gid+0x35>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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