#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 {
  void *pw_shell;
  void *pw_dir;
  void *pw_gecos;
  void *pw_passwd;
  void *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(struct passwd *, struct passwd *, int);
void *strncpy(char *, void *, int);
struct passwd *np_copy_passwd(struct passwd *old_pwd) {
  static char new_name[100];
  static char new_passwd[100];
  static char new_gecos[100];
  static char new_dir[100];
  static char new_shell[100];
  static struct passwd new_pwd;
  memcpy(&new_pwd, old_pwd, sizeof(struct passwd));
  new_pwd.pw_name = strncpy(new_name, old_pwd->pw_name, 100);
  new_pwd.pw_passwd = strncpy(new_passwd, old_pwd->pw_passwd, 100);
  new_pwd.pw_gecos = strncpy(new_gecos, old_pwd->pw_gecos, 100);
  new_pwd.pw_dir = strncpy(new_dir, old_pwd->pw_dir, 100);
  new_pwd.pw_shell = strncpy(new_shell, old_pwd->pw_shell, 100);
  return &new_pwd;
}


x86 assembly (clang, -O0):
<np_copy_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x3131(%rip),%rdi
mov    $0x28,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0x2ef0(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x3127(%rip)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0x2f40(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x30ff(%rip)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0x2f90(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x30d7(%rip)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0x2fe0(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x30af(%rip)
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0x3031(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x3088(%rip)
lea    0x3081(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<np_copy_passwd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x313a(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
mov    0x20(%rbx),%rsi
lea    0x2ef7(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x312e(%rip)
mov    0x18(%rbx),%rsi
lea    0x2f4b(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x310a(%rip)
mov    0x10(%rbx),%rsi
lea    0x2f9f(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x30e6(%rip)
mov    0x8(%rbx),%rsi
lea    0x2ff3(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x30c2(%rip)
mov    (%rbx),%rsi
lea    0x3048(%rip),%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rax,0x309f(%rip)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8* }
@np_copy_passwd.new_name = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_passwd = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_gecos = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_dir = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_shell = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_pwd = internal global %struct.passwd zeroinitializer
define %struct.passwd* @np_copy_passwd(%struct.passwd* %0) {
%2 = alloca %struct.passwd*
store %struct.passwd* %0, %struct.passwd** %2
%3 = load %struct.passwd*, %struct.passwd** %2
%4 = call i32 @memcpy(%struct.passwd* @np_copy_passwd.new_pwd, %struct.passwd* %3, i32 40)
%5 = load %struct.passwd*, %struct.passwd** %2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i32 0, i32 4
%7 = load i8*, i8** %6
%8 = call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_name, i64 0, i64 0), i8* %7, i32 100)
store i8* %8, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i32 0, i32 4)
%9 = load %struct.passwd*, %struct.passwd** %2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 3
%11 = load i8*, i8** %10
%12 = call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_passwd, i64 0, i64 0), i8* %11, i32 100)
store i8* %12, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i32 0, i32 3)
%13 = load %struct.passwd*, %struct.passwd** %2
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 2
%15 = load i8*, i8** %14
%16 = call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_gecos, i64 0, i64 0), i8* %15, i32 100)
store i8* %16, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i32 0, i32 2)
%17 = load %struct.passwd*, %struct.passwd** %2
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 1
%19 = load i8*, i8** %18
%20 = call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_dir, i64 0, i64 0), i8* %19, i32 100)
store i8* %20, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i32 0, i32 1)
%21 = load %struct.passwd*, %struct.passwd** %2
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_shell, i64 0, i64 0), i8* %23, i32 100)
store i8* %24, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i32 0, i32 0)
ret %struct.passwd* @np_copy_passwd.new_pwd
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8* }
@np_copy_passwd.new_name = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_passwd = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_gecos = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_dir = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_shell = internal global [100 x i8] zeroinitializer
@np_copy_passwd.new_pwd = internal global %struct.passwd zeroinitializer
define %struct.passwd* @np_copy_passwd(%struct.passwd* %0) {
%2 = tail call i32 @memcpy(%struct.passwd* @np_copy_passwd.new_pwd, %struct.passwd* %0, i32 40)
%3 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 4
%4 = load i8*, i8** %3
%5 = tail call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_name, i64 0, i64 0), i8* %4, i32 100)
store i8* %5, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i64 0, i32 4)
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 3
%7 = load i8*, i8** %6
%8 = tail call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_passwd, i64 0, i64 0), i8* %7, i32 100)
store i8* %8, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i64 0, i32 3)
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 2
%10 = load i8*, i8** %9
%11 = tail call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_gecos, i64 0, i64 0), i8* %10, i32 100)
store i8* %11, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i64 0, i32 2)
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%13 = load i8*, i8** %12
%14 = tail call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_dir, i64 0, i64 0), i8* %13, i32 100)
store i8* %14, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i64 0, i32 1)
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i8* @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @np_copy_passwd.new_shell, i64 0, i64 0), i8* %16, i32 100)
store i8* %17, i8** getelementptr inbounds (%struct.passwd, %struct.passwd* @np_copy_passwd.new_pwd, i64 0, i32 0)
ret %struct.passwd* @np_copy_passwd.new_pwd
}