int main() {
  char str1[] = "To be or not to be";
  char str2[40] = {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
  char str3[40] = {0x31};
  strncpy(str2, str1, sizeof(str2));
  strncpy(str3, str2, 5);
  str3[5] = '\0';
  puts(str1);
  puts(str2);
  puts(str3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea1(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xe99(%rip),%al
mov    %al,-0xe(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movb   $0x31,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x28,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x7b(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1040 <puts@plt>
lea    -0x50(%rbp),%rdi
mov    $0x0,%al
call   1040 <puts@plt>
lea    -0x80(%rbp),%rdi
mov    $0x0,%al
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
movaps 0xecd(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x656220,0xf(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0x50(%rsp),%rbx
mov    %rsp,%r14
mov    $0x28,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
lea    0x20(%rsp),%r15
mov    $0x5,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <puts@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str1 = [19 x i8] c"To be or not to be\00"
@__const.main.str2 = [40 x i8] c"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [19 x i8]
%3 = alloca [40 x i8]
%4 = alloca [40 x i8]
store i32 0, i32* %1
%5 = bitcast [19 x i8]* %2 to i8*
%6 = bitcast [40 x i8]* %3 to i8*
%7 = bitcast [40 x i8]* %4 to i8*
%8 = bitcast i8* %7 to <{ i8, [39 x i8] }>*
%9 = getelementptr inbounds <{ i8, [39 x i8] }>, <{ i8, [39 x i8] }>* %8, i32 0, i32 0
store i8 49, i8* %9
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%12 = call i8* @strncpy(i8* %10, i8* %11, i64 40)
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%15 = call i8* @strncpy(i8* %13, i8* %14, i64 5)
%16 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 5
store i8 0, i8* %16
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %17)
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %19)
%21 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str1 = [19 x i8] c"To be or not to be\00"
define i32 @main() {
%1 = alloca [19 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = call i8* @strncpy(i8* %5, i8* %4, i64 40)
%8 = call i8* @strncpy(i8* %6, i8* %5, i64 5)
%9 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %4)
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %5)
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @puts to i32 (i8*, ...)*)(i8* %6)
ret i32 0
}