#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 {
  scalar_t__ pw_gid;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int slurm_getpwuid_r(int /*<<< orphan*/, struct passwd *, char *, int,
                     struct passwd **);
gid_t gid_from_uid(uid_t uid) {
  struct passwd pwd, *result;
  char buffer[65536];
  gid_t gid;
  int rc;
  rc = slurm_getpwuid_r(uid, &pwd, buffer, 65536, &result);
  if (result && (rc == 0))
    gid = result->pw_gid;
  else
    gid = (gid_t)-1;
  return gid;
}


x86 assembly (clang, -O0):
<gid_from_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10020(%rbp),%rdx
lea    -0x10(%rbp),%rsi
mov    $0x10000,%ecx
lea    -0x18(%rbp),%r8
call   1030 <slurm_getpwuid_r@plt>
mov    %eax,-0x1002c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116b <gid_from_uid+0x5b>
cmpl   $0x0,-0x1002c(%rbp)
jne    116b <gid_from_uid+0x5b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10028(%rbp)
jmp    1176 <gid_from_uid+0x66>
movq   $0xffffffffffffffff,-0x10028(%rbp)
ff ff ff ff
mov    -0x10028(%rbp),%rax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gid_from_uid>:
sub    $0x10018,%rsp
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%r8
mov    $0x10000,%ecx
call   1030 <slurm_getpwuid_r@plt>
mov    %eax,%ecx
mov    (%rsp),%rdx
mov    $0xffffffffffffffff,%rax
test   %rdx,%rdx
je     1147 <gid_from_uid+0x37>
test   %ecx,%ecx
jne    1147 <gid_from_uid+0x37>
mov    (%rdx),%rax
add    $0x10018,%rsp
ret

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

LLVM IR (-O2):
%struct.passwd = type { i64 }
define i64 @gid_from_uid(i32 %0) {
%2 = alloca %struct.passwd
%3 = alloca %struct.passwd*
%4 = alloca [65536 x i8]
%5 = bitcast %struct.passwd* %2 to i8*
%6 = bitcast %struct.passwd** %3 to i8*
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%8 = call i32 @slurm_getpwuid_r(i32 %0, %struct.passwd* %2, i8* %7, i32 65536, %struct.passwd** %3)
%9 = load %struct.passwd*, %struct.passwd** %3
%10 = icmp ne %struct.passwd* %9, null
%11 = icmp eq i32 %8, 0
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 0
%15 = load i64, i64* %14
br label %16
16: ; preds = %1, %13
%17 = phi i64 [ %15, %13 ], [ -1, %1 ]
ret i64 %17
}