#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 {
  int pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ EX_NOUSER;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
struct passwd *getpwnam(char const *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int /*<<< orphan*/ strtol(char const *, char **, int);
int /*<<< orphan*/ usage();
void parse_uid(const char *s, char *buf, size_t bufsize) {
  struct passwd *pw;
  char *inval;
  if ((pw = getpwnam(s)) != NULL)
    snprintf(buf, bufsize, "%d", pw->pw_uid);
  else {
    strtol(s, &inval, 10);
    if (*inval != 0) {
      errx(EX_NOUSER, "unknown user id: %s", s);
      usage();
    } else {
      strncpy(buf, s, bufsize);
    }
  }
}


x86 assembly (clang, -O0):
<parse_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11aa <parse_uid+0x4a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe60(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1207 <parse_uid+0xa7>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f1 <parse_uid+0x91>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1040 <errx@plt>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    1202 <parse_uid+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
jmp    1207 <parse_uid+0xa7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uid>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <getpwnam@plt>
test   %rax,%rax
je     1199 <parse_uid+0x39>
mov    (%rax),%ecx
lea    0xe7b(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11dd <parse_uid+0x7d>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdx
call   1040 <errx@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <usage@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [3 x i8] c"%d\00"
@EX_NOUSER = global i32 0
@.str.1 = [20 x i8] c"unknown user id: %s\00"
define void @parse_uid(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.passwd*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call %struct.passwd* @getpwnam(i8* %9)
store %struct.passwd* %10, %struct.passwd** %7
%11 = icmp ne %struct.passwd* %10, null
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i64, i64* %6
%15 = load %struct.passwd*, %struct.passwd** %7
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @snprintf(i8* %13, i64 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %37
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = call i32 @strtol(i8* %20, i8** %8, i32 10)
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* @EX_NOUSER
%28 = load i8*, i8** %4
%29 = call i32 @errx(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 (...) @usage()
br label %36
31: ; preds = %19
%32 = load i8*, i8** %5
%33 = load i8*, i8** %4
%34 = load i64, i64* %6
%35 = call i32 @strncpy(i8* %32, i8* %33, i64 %34)
br label %36
36: ; preds = %31, %26
br label %37
37: ; preds = %36, %12
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [3 x i8] c"%d\00"
@EX_NOUSER = global i32 0
@.str.1 = [20 x i8] c"unknown user id: %s\00"
define void @parse_uid(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call %struct.passwd* @getpwnam(i8* %0)
%7 = icmp eq %struct.passwd* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %23
12: ; preds = %3
%13 = call i32 @strtol(i8* %0, i8** %4, i32 10)
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @EX_NOUSER
%19 = tail call i32 @errx(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = tail call i32 (...) @usage()
br label %23
21: ; preds = %12
%22 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %2)
br label %23
23: ; preds = %17, %21, %8
ret void
}