#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 */
typedef int /*<<< orphan*/ str2;

/* Variables and functions */
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char str1[] = "hello world";
  char str2[40];
  char str3[40];
  strncpy(str2, str1, sizeof(str2));
  strncpy(str3, str2, 3);
  str3[3] = '\0';
  puts(str1);
  puts(str2);
  puts(str3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x28,%edx
call   1030 <strncpy@plt>
lea    -0x70(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x6d(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x40(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x70(%rbp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,(%rsp)
movl   $0x646c72,0x8(%rsp)
lea    0x40(%rsp),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x28,%edx
call   1030 <strncpy@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x13(%rsp)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str1 = [12 x i8] c"hello world\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = bitcast [12 x i8]* %1 to i8*
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%7 = call i32 @strncpy(i8* %5, i8* %6, i32 40)
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 3)
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 3
store i8 0, i8* %11
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%13 = call i32 @puts(i8* %12)
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%15 = call i32 @puts(i8* %14)
%16 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%17 = call i32 @puts(i8* %16)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str1 = [12 x i8] c"hello world\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [12 x i8], [12 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 i32 @strncpy(i8* %5, i8* %4, i32 40)
%8 = call i32 @strncpy(i8* %6, i8* %5, i32 3)
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 3
store i8 0, i8* %9
%10 = call i32 @puts(i8* %4)
%11 = call i32 @puts(i8* %5)
%12 = call i32 @puts(i8* %6)
ret i32 0
}