#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
char *stpncpy(char *, char const *, int);
int main(int argc, char *argv[]) {
  char buf[64] = "abcdefghijklmnopqrstuvwxyz";
  const char *src = "helloworld";
  char *p;
  p = stpncpy(buf, src, 0);
  assert(p == buf);
  p = stpncpy(buf, src, 5);
  assert(p == buf + 5);
  p = stpncpy(buf, src, 10);
  assert(p == buf + 10);
  p = stpncpy(buf, src, 11);
  assert(p == buf + 10);
  p = stpncpy(buf, src, 12);
  assert(p == buf + 10);
  p = stpncpy(buf, src, 20);
  assert(p == buf + 10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    0xede(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0x5,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0x5,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0xa,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0xb,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0xc,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    $0x14,%edx
call   1050 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
movaps 0xf00(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee1(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <stpncpy@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <stpncpy@plt>
lea    0x5(%rsp),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <stpncpy@plt>
lea    0xa(%rsp),%r15
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xb,%edx
call   1040 <stpncpy@plt>
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
call   1040 <stpncpy@plt>
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x14,%edx
call   1040 <stpncpy@plt>
xor    %edi,%edi
cmp    %r15,%rax
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.buf = [64 x i8] c"abcdefghijklmnopqrstuvwxyz\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [11 x i8] c"helloworld\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [64 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [64 x i8]* %6 to i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %7
%12 = call i8* @stpncpy(i8* %10, i8* %11, i32 0)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%15 = icmp eq i8* %13, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%19 = load i8*, i8** %7
%20 = call i8* @stpncpy(i8* %18, i8* %19, i32 5)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 5
%24 = icmp eq i8* %21, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = call i8* @stpncpy(i8* %27, i8* %28, i32 10)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 10
%33 = icmp eq i8* %30, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%37 = load i8*, i8** %7
%38 = call i8* @stpncpy(i8* %36, i8* %37, i32 11)
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%41 = getelementptr inbounds i8, i8* %40, i64 10
%42 = icmp eq i8* %39, %41
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%46 = load i8*, i8** %7
%47 = call i8* @stpncpy(i8* %45, i8* %46, i32 12)
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%50 = getelementptr inbounds i8, i8* %49, i64 10
%51 = icmp eq i8* %48, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%55 = load i8*, i8** %7
%56 = call i8* @stpncpy(i8* %54, i8* %55, i32 20)
store i8* %56, i8** %8
%57 = load i8*, i8** %8
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%59 = getelementptr inbounds i8, i8* %58, i64 10
%60 = icmp eq i8* %57, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [64 x i8] c"abcdefghijklmnopqrstuvwxyz\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [11 x i8] c"helloworld\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = icmp eq i8* %5, %4
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 5)
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 5
%11 = icmp eq i8* %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 10
%16 = icmp eq i8* %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 11)
%20 = icmp eq i8* %19, %15
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 12)
%24 = icmp eq i8* %23, %15
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i8* @stpncpy(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 20)
%28 = icmp eq i8* %27, %15
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
ret i32 0
}