#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 /*<<< orphan*/ pw_dir;
  int /*<<< orphan*/ pw_shell;
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int EINVAL;
int ENOMEM;
int /*<<< orphan*/ asprintf(char **, char *, int /*<<< orphan*/);
char *strdup(int /*<<< orphan*/);
int specifier_user_pwd(char specifier, void *data,
                       void __attribute__((unused)) * userdata, char **ret) {
  struct passwd *pwd = data;
  char *n = NULL;
  switch (specifier) {
  case 'u':
    n = strdup(pwd->pw_name);
    break;
  case 'U':
    asprintf(&n, "%d", pwd->pw_uid);
    break;
  case 's':
    n = strdup(pwd->pw_shell);
    break;
  case 'h':
    n = strdup(pwd->pw_dir);
    break;
  default:
    return -EINVAL;
  }
  if (!n)
    return -ENOMEM;
  *ret = n;
  return 0;
}


x86 assembly (clang, -O0):
<specifier_user_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movsbl -0x5(%rbp),%eax
add    $0xffffffab,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x20,%eax
ja     11ce <specifier_user_pwd+0xae>
mov    -0x38(%rbp),%rax
lea    0xe95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%edi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    11e1 <specifier_user_pwd+0xc1>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
lea    -0x30(%rbp),%rdi
lea    0xee9(%rip),%rsi
call   1030 <asprintf@plt>
jmp    11e1 <specifier_user_pwd+0xc1>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    11e1 <specifier_user_pwd+0xc1>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    11e1 <specifier_user_pwd+0xc1>
xor    %eax,%eax
mov    0x2e01(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1211 <specifier_user_pwd+0xf1>
cmpq   $0x0,-0x30(%rbp)
jne    11ff <specifier_user_pwd+0xdf>
xor    %eax,%eax
mov    0x2deb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1211 <specifier_user_pwd+0xf1>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<specifier_user_pwd>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
add    $0xffffffab,%edi
cmp    $0x20,%edi
ja     1170 <specifier_user_pwd+0x50>
mov    %rcx,%rbx
lea    0xec0(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    0x8(%rsi),%edx
lea    0xf31(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <asprintf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jne    1193 <specifier_user_pwd+0x73>
mov    0x2e72(%rip),%rcx
jmp    1177 <specifier_user_pwd+0x57>
mov    0x2e61(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1198 <specifier_user_pwd+0x78>
mov    (%rsi),%edi
jmp    1189 <specifier_user_pwd+0x69>
mov    0x4(%rsi),%edi
jmp    1189 <specifier_user_pwd+0x69>
mov    0xc(%rsi),%edi
call   1040 <strdup@plt>
test   %rax,%rax
je     1167 <specifier_user_pwd+0x47>
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @specifier_user_pwd(i8 signext %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca %struct.passwd*
%11 = alloca i8*
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%12 = load i8*, i8** %7
%13 = bitcast i8* %12 to %struct.passwd*
store %struct.passwd* %13, %struct.passwd** %10
store i8* null, i8** %11
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
switch i32 %15, label %36 [
i32 117, label %16
i32 85, label %21
i32 115, label %26
i32 104, label %31
]
16: ; preds = %4
%17 = load %struct.passwd*, %struct.passwd** %10
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 3
%19 = load i32, i32* %18
%20 = call i8* @strdup(i32 %19)
store i8* %20, i8** %11
br label %39
21: ; preds = %4
%22 = load %struct.passwd*, %struct.passwd** %10
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %39
26: ; preds = %4
%27 = load %struct.passwd*, %struct.passwd** %10
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i8* @strdup(i32 %29)
store i8* %30, i8** %11
br label %39
31: ; preds = %4
%32 = load %struct.passwd*, %struct.passwd** %10
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i8* @strdup(i32 %34)
store i8* %35, i8** %11
br label %39
36: ; preds = %4
%37 = load i32, i32* @EINVAL
%38 = sub nsw i32 0, %37
store i32 %38, i32* %5
br label %48
39: ; preds = %31, %26, %21, %16
%40 = load i8*, i8** %11
%41 = icmp ne i8* %40, null
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* @ENOMEM
%44 = sub nsw i32 0, %43
store i32 %44, i32* %5
br label %48
45: ; preds = %39
%46 = load i8*, i8** %11
%47 = load i8**, i8*** %9
store i8* %46, i8** %47
store i32 0, i32* %5
br label %48
48: ; preds = %45, %42, %36
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @specifier_user_pwd(i8 signext %0, i8* nocapture %1, i8* nocapture readnone %2, i8** nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%7 = sext i8 %0 to i32
switch i32 %7, label %28 [
i32 117, label %8
i32 85, label %13
i32 115, label %19
i32 104, label %24
]
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %1, i64 12
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = tail call i8* @strdup(i32 %11)
br label %31
13: ; preds = %4
%14 = getelementptr inbounds i8, i8* %1, i64 8
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %5
br label %31
19: ; preds = %4
%20 = getelementptr inbounds i8, i8* %1, i64 4
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = tail call i8* @strdup(i32 %22)
br label %31
24: ; preds = %4
%25 = bitcast i8* %1 to i32*
%26 = load i32, i32* %25
%27 = tail call i8* @strdup(i32 %26)
br label %31
28: ; preds = %4
%29 = load i32, i32* @EINVAL
%30 = sub nsw i32 0, %29
br label %38
31: ; preds = %24, %19, %13, %8
%32 = phi i8* [ %27, %24 ], [ %23, %19 ], [ %18, %13 ], [ %12, %8 ]
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* @ENOMEM
%36 = sub nsw i32 0, %35
br label %38
37: ; preds = %31
store i8* %32, i8** %3
br label %38
38: ; preds = %37, %34, %28
%39 = phi i32 [ %30, %28 ], [ 0, %37 ], [ %36, %34 ]
ret i32 %39
}