#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 {
  char *pw_name;
  int pw_uid;
  int pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
void get_data_for_user(char *dst, struct passwd *pw, char *options) {
  bool c = true;
  char integer[sizeof(int)];
  for (int i = 0; i < 6; i++) {
    if (options[i] == '\0')
      break;
    if (c)
      c = false;
    else
      strcat(dst, " ");
    switch (options[i]) {
    case 'L':
      strcat(dst, pw->pw_name);
      break;
    case 'U':
      sprintf(integer, "%d", pw->pw_uid);
      strcat(dst, integer);
      break;
    case 'G':
      sprintf(integer, "%d", pw->pw_gid);
      strcat(dst, integer);
      break;
    case 'N':
      strcat(dst, pw->pw_gecos);
      break;
    case 'H':
      strcat(dst, pw->pw_dir);
      break;
    case 'S':
      strcat(dst, pw->pw_shell);
      break;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<get_data_for_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    1275 <get_data_for_user+0x155>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1166 <get_data_for_user+0x46>
jmp    1275 <get_data_for_user+0x155>
cmpl   $0x0,-0x1c(%rbp)
je     117c <get_data_for_user+0x5c>
movl   $0x0,-0x1c(%rbp)
jmp    118c <get_data_for_user+0x6c>
mov    -0x8(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffb9,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xe,%eax
ja     1262 <get_data_for_user+0x142>
mov    -0x30(%rbp),%rax
lea    0xe4b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcat@plt>
jmp    1262 <get_data_for_user+0x142>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe59(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcat@plt>
jmp    1262 <get_data_for_user+0x142>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edx
lea    0xe30(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcat@plt>
jmp    1262 <get_data_for_user+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcat@plt>
jmp    1262 <get_data_for_user+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <strcat@plt>
jmp    1262 <get_data_for_user+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1030 <strcat@plt>
jmp    1267 <get_data_for_user+0x147>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <get_data_for_user+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_for_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r13d,%r13d
lea    0xec2(%rip),%r12
lea    0x4(%rsp),%rbp
xor    %eax,%eax
jmp    115f <get_data_for_user+0x3f>
mov    0x20(%r14),%rsi
mov    %r15,%rdi
call   1030 <strcat@plt>
add    $0x1,%r13
mov    $0x1,%al
cmp    $0x6,%r13
je     11c6 <get_data_for_user+0xa6>
movzbl (%rbx,%r13,1),%ecx
test   %cl,%cl
je     11c6 <get_data_for_user+0xa6>
test   $0x1,%al
je     1180 <get_data_for_user+0x60>
mov    %r15,%rdi
lea    0xec6(%rip),%rsi
call   1030 <strcat@plt>
movzbl (%rbx,%r13,1),%ecx
movsbl %cl,%eax
add    $0xffffffb9,%eax
cmp    $0xe,%eax
ja     1153 <get_data_for_user+0x33>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0xc(%r14),%edx
jmp    11af <get_data_for_user+0x8f>
mov    0x18(%r14),%rsi
jmp    114b <get_data_for_user+0x2b>
mov    (%r14),%rsi
jmp    114b <get_data_for_user+0x2b>
mov    0x10(%r14),%rsi
jmp    114b <get_data_for_user+0x2b>
mov    0x8(%r14),%edx
mov    %rbp,%rdi
lea    0xe85(%rip),%rsi
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
jmp    114e <get_data_for_user+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%d\00"
define void @get_data_for_user(i8* %0, %struct.passwd* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.passwd*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store %struct.passwd* %1, %struct.passwd** %5
store i8* %2, i8** %6
store i32 1, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %79, %3
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 6
br i1 %12, label %13, label %82
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
br label %82
22: ; preds = %13
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %7
br label %29
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %26, %25
%30 = load i8*, i8** %6
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %78 [
i32 76, label %36
i32 85, label %42
i32 71, label %51
i32 78, label %60
i32 72, label %66
i32 83, label %72
]
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load %struct.passwd*, %struct.passwd** %5
%39 = getelementptr inbounds %struct.passwd, %struct.passwd* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 @strcat(i8* %37, i8* %40)
br label %78
42: ; preds = %29
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%44 = load %struct.passwd*, %struct.passwd** %5
%45 = getelementptr inbounds %struct.passwd, %struct.passwd* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %4
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%50 = call i32 @strcat(i8* %48, i8* %49)
br label %78
51: ; preds = %29
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%53 = load %struct.passwd*, %struct.passwd** %5
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i32 0, i32 2
%55 = load i32, i32* %54
%56 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i8*, i8** %4
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%59 = call i32 @strcat(i8* %57, i8* %58)
br label %78
60: ; preds = %29
%61 = load i8*, i8** %4
%62 = load %struct.passwd*, %struct.passwd** %5
%63 = getelementptr inbounds %struct.passwd, %struct.passwd* %62, i32 0, i32 3
%64 = load i8*, i8** %63
%65 = call i32 @strcat(i8* %61, i8* %64)
br label %78
66: ; preds = %29
%67 = load i8*, i8** %4
%68 = load %struct.passwd*, %struct.passwd** %5
%69 = getelementptr inbounds %struct.passwd, %struct.passwd* %68, i32 0, i32 4
%70 = load i8*, i8** %69
%71 = call i32 @strcat(i8* %67, i8* %70)
br label %78
72: ; preds = %29
%73 = load i8*, i8** %4
%74 = load %struct.passwd*, %struct.passwd** %5
%75 = getelementptr inbounds %struct.passwd, %struct.passwd* %74, i32 0, i32 5
%76 = load i8*, i8** %75
%77 = call i32 @strcat(i8* %73, i8* %76)
br label %78
78: ; preds = %29, %72, %66, %60, %51, %42, %36
br label %79
79: ; preds = %78
%80 = load i32, i32* %9
%81 = add nsw i32 %80, 1
store i32 %81, i32* %9
br label %10
82: ; preds = %21, %10
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i32, i32, i8*, i8*, i8* }
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%d\00"
define void @get_data_for_user(i8* %0, %struct.passwd* nocapture %1, i8* nocapture %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 5
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 4
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 3
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 1
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 0
br label %12
12: ; preds = %3, %45
%13 = phi i64 [ 0, %3 ], [ %46, %45 ]
%14 = phi i1 [ false, %3 ], [ true, %45 ]
%15 = getelementptr inbounds i8, i8* %2, i64 %13
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %48, label %18
18: ; preds = %12
br i1 %14, label %19, label %22
19: ; preds = %18
%20 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i8, i8* %15
br label %22
22: ; preds = %18, %19
%23 = phi i8 [ %16, %18 ], [ %21, %19 ]
%24 = sext i8 %23 to i32
switch i32 %24, label %45 [
i32 76, label %25
i32 85, label %28
i32 71, label %32
i32 78, label %36
i32 72, label %39
i32 83, label %42
]
25: ; preds = %22
%26 = load i8*, i8** %11
%27 = call i32 @strcat(i8* %0, i8* %26)
br label %45
28: ; preds = %22
%29 = load i32, i32* %10
%30 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call i32 @strcat(i8* %0, i8* %5)
br label %45
32: ; preds = %22
%33 = load i32, i32* %9
%34 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = call i32 @strcat(i8* %0, i8* %5)
br label %45
36: ; preds = %22
%37 = load i8*, i8** %8
%38 = call i32 @strcat(i8* %0, i8* %37)
br label %45
39: ; preds = %22
%40 = load i8*, i8** %7
%41 = call i32 @strcat(i8* %0, i8* %40)
br label %45
42: ; preds = %22
%43 = load i8*, i8** %6
%44 = call i32 @strcat(i8* %0, i8* %43)
br label %45
45: ; preds = %25, %28, %32, %36, %39, %42, %22
%46 = add nuw nsw i64 %13, 1
%47 = icmp eq i64 %46, 6
br i1 %47, label %48, label %12
48: ; preds = %12, %45
ret void
}