#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 dummy;
};

/* Variables and functions */
struct passwd *getpwnam(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
char *strtok_r(char *, char *, char **);
int /*<<< orphan*/ strtol(char *, char **, int);
struct passwd *get_next_user(char **endptr, bool uid_or_name, void *user) {
  struct passwd *pw;
  if (uid_or_name) {
    *(uid_t *)user = strtol(*endptr, endptr, 10);
    return getpwuid(*(uid_t *)user);
  } else {
    *(char **)user = strtok_r(*endptr, " ", endptr);
    pw = getpwnam(*(char **)user);
    return pw;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_next_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <get_next_user+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
jmp    11c7 <get_next_user+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe60(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_user>:
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%rdx
mov    (%rdi),%rdi
test   %esi,%esi
je     1165 <get_next_user+0x25>
mov    %rdx,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,(%rbx)
mov    %eax,%edi
pop    %rbx
jmp    1030 <getpwuid@plt>
lea    0xe94(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
pop    %rbx
jmp    1050 <getpwnam@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [2 x i8] c" \00"
define %struct.passwd* @get_next_user(i8** %0, i32 %1, i8* %2) {
%4 = alloca %struct.passwd*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.passwd*
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = call i32 @strtol(i8* %13, i8** %14, i32 10)
%16 = load i8*, i8** %7
%17 = bitcast i8* %16 to i32*
store i32 %15, i32* %17
%18 = load i8*, i8** %7
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
%21 = call %struct.passwd* @getpwuid(i32 %20)
store %struct.passwd* %21, %struct.passwd** %4
br label %34
22: ; preds = %3
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %5
%26 = call i8* @strtok_r(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %25)
%27 = load i8*, i8** %7
%28 = bitcast i8* %27 to i8**
store i8* %26, i8** %28
%29 = load i8*, i8** %7
%30 = bitcast i8* %29 to i8**
%31 = load i8*, i8** %30
%32 = call %struct.passwd* @getpwnam(i8* %31)
store %struct.passwd* %32, %struct.passwd** %8
%33 = load %struct.passwd*, %struct.passwd** %8
store %struct.passwd* %33, %struct.passwd** %4
br label %34
34: ; preds = %22, %11
%35 = load %struct.passwd*, %struct.passwd** %4
ret %struct.passwd* %35
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [2 x i8] c" \00"
define %struct.passwd* @get_next_user(i8** %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp eq i32 %1, 0
%5 = load i8*, i8** %0
br i1 %4, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @strtol(i8* %5, i8** %0, i32 10)
%8 = bitcast i8* %2 to i32*
store i32 %7, i32* %8
%9 = tail call %struct.passwd* @getpwuid(i32 %7)
br label %14
10: ; preds = %3
%11 = tail call i8* @strtok_r(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %0)
%12 = bitcast i8* %2 to i8**
store i8* %11, i8** %12
%13 = tail call %struct.passwd* @getpwnam(i8* %11)
br label %14
14: ; preds = %10, %6
%15 = phi %struct.passwd* [ %9, %6 ], [ %13, %10 ]
ret %struct.passwd* %15
}