#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;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ getgid();
int getpwnam_r(char const *, struct passwd *, char *, int, struct passwd **);
int /*<<< orphan*/ getuid();
int os_uinfo(uid_t *uid, gid_t *gid, const char *user) {
  char buf[1024];
  int istat;
  struct passwd pwinfo, *pwinfo2;
  if (!user) {
    errno = EINVAL;
    return (-1);
  } else if (!(*user)) {
    if (uid)
      *uid = getuid();
    if (gid)
      *gid = getgid();
  }
  istat = getpwnam_r(user, &pwinfo, buf, sizeof(buf), &pwinfo2);
  if (istat)
    return (-1);
  if (uid)
    *uid = pwinfo.pw_uid;
  if (gid)
    *gid = pwinfo.pw_gid;
  return (0);
}


x86 assembly (clang, -O0):
<os_uinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1170 <os_uinfo+0x40>
mov    0x2e7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <os_uinfo+0x102>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11b6 <os_uinfo+0x86>
cmpq   $0x0,-0x10(%rbp)
je     1197 <os_uinfo+0x67>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <os_uinfo+0x81>
mov    $0x0,%al
call   1040 <getgid@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b6 <os_uinfo+0x86>
jmp    11bb <os_uinfo+0x8b>
mov    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    -0x430(%rbp),%rsi
mov    $0x400,%ecx
lea    -0x438(%rbp),%r8
call   1050 <getpwnam_r@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     11fd <os_uinfo+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <os_uinfo+0x102>
cmpq   $0x0,-0x10(%rbp)
je     1214 <os_uinfo+0xe4>
mov    -0x42c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     122b <os_uinfo+0xfb>
mov    -0x430(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_uinfo>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
test   %rdx,%rdx
je     11ad <os_uinfo+0x7d>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
cmpb   $0x0,(%rdx)
jne    116d <os_uinfo+0x3d>
test   %r15,%r15
je     115e <os_uinfo+0x2e>
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,(%r15)
test   %r14,%r14
je     116d <os_uinfo+0x3d>
xor    %eax,%eax
call   1040 <getgid@plt>
mov    %eax,(%r14)
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    $0x400,%ecx
call   1050 <getpwnam_r@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    11c4 <os_uinfo+0x94>
test   %r15,%r15
je     119e <os_uinfo+0x6e>
mov    0x4(%rsp),%eax
mov    %eax,(%r15)
xor    %eax,%eax
test   %r14,%r14
je     11c4 <os_uinfo+0x94>
mov    (%rsp),%ecx
mov    %ecx,(%r14)
jmp    11c4 <os_uinfo+0x94>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    0x2e23(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @os_uinfo(i32* writeonly %0, i32* writeonly %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.passwd
%6 = alloca %struct.passwd*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.passwd* %5 to i8*
%9 = bitcast %struct.passwd** %6 to i8*
%10 = icmp eq i8* %2, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
br label %37
13: ; preds = %3
%14 = load i8, i8* %2
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = icmp eq i32* %0, null
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 (...) @getuid()
store i32 %19, i32* %0
br label %20
20: ; preds = %18, %16
%21 = icmp eq i32* %1, null
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = tail call i32 (...) @getgid()
store i32 %23, i32* %1
br label %24
24: ; preds = %13, %22, %20
%25 = call i32 @getpwnam_r(i8* %2, %struct.passwd* %5, i8* %7, i32 1024, %struct.passwd** %6)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = icmp eq i32* %0, null
br i1 %28, label %32, label %29
29: ; preds = %27
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 1
%31 = load i32, i32* %30
store i32 %31, i32* %0
br label %32
32: ; preds = %29, %27
%33 = icmp eq i32* %1, null
br i1 %33, label %37, label %34
34: ; preds = %32
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %1
br label %37
37: ; preds = %32, %34, %24, %11
%38 = phi i32 [ -1, %11 ], [ -1, %24 ], [ 0, %34 ], [ 0, %32 ]
ret i32 %38
}