#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 passwd {
  scalar_t__ pw_gid;
  scalar_t__ pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ _SC_GETPW_R_SIZE_MAX;
int getpwnam_r(int /*<<< orphan*/, struct passwd *, char *, size_t,
               struct passwd **);
int /*<<< orphan*/ optarg;
char *smm_alloc(size_t);
int smm_errno_update(int);
int /*<<< orphan*/ smm_free(char *);
size_t sysconf(int /*<<< orphan*/);
int smm_pwuid(char *uname, long *uid, long *gid) {
  struct passwd pwd, *result;
  char *buf;
  int rc;
  size_t bufsize;
  (void)uname;
  bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if (bufsize == (size_t)-1) {
    bufsize = 16384;
  }
  if ((buf = smm_alloc(bufsize)) == NULL) {
    return smm_errno_update((0xC0000000 | (1)));
  }
  if ((rc = getpwnam_r(optarg, &pwd, buf, bufsize, &result)) != 0) {
    rc = smm_errno_update((0xC0000000 | (10)));
  } else {
    if (uid) {
      *uid = (long)pwd.pw_uid;
    }
    if (gid) {
      *gid = (long)pwd.pw_gid;
    }
  }
  smm_free(buf);
  return rc;
}


x86 assembly (clang, -O0):
<smm_pwuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0xffffffffffffffff,-0x50(%rbp)
jne    1189 <smm_pwuid+0x39>
movq   $0x4000,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <smm_alloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11b2 <smm_pwuid+0x62>
mov    $0xc0000001,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,-0x4(%rbp)
jmp    122e <smm_pwuid+0xde>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
mov    -0x50(%rbp),%rcx
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%r8
call   1050 <getpwnam_r@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     11ee <smm_pwuid+0x9e>
mov    $0xc000000a,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,-0x44(%rbp)
jmp    121f <smm_pwuid+0xcf>
cmpq   $0x0,-0x18(%rbp)
je     1204 <smm_pwuid+0xb4>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     121a <smm_pwuid+0xca>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    121f <smm_pwuid+0xcf>
mov    -0x40(%rbp),%rdi
call   1060 <smm_free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smm_pwuid>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x4000,%ebx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1030 <smm_alloc@plt>
test   %rax,%rax
je     11ba <smm_pwuid+0x6a>
mov    %rax,%r12
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
lea    0x10(%rsp),%r8
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <getpwnam_r@plt>
test   %eax,%eax
je     11cf <smm_pwuid+0x7f>
mov    $0xc000000a,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,%ebx
jmp    11ea <smm_pwuid+0x9a>
mov    $0xc0000001,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <smm_errno_update@plt>
test   %r15,%r15
je     11dc <smm_pwuid+0x8c>
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
xor    %ebx,%ebx
test   %r14,%r14
je     11ea <smm_pwuid+0x9a>
mov    (%rsp),%rax
mov    %rax,(%r14)
mov    %r12,%rdi
call   1060 <smm_free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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