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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char buff[4];
  char *str = "0123456";
  strncpy(buff, str, sizeof(buff));
  printf("[%s] sizeof:%lu\n", buff, sizeof(buff));
  snprintf(buff, sizeof(buff), "%s", str);
  printf("[%s] sizeof:%lu\n", buff, sizeof(buff));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x4(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x4(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x4,%edx
call   1040 <printf@plt>
lea    -0x4(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
lea    0xe9b(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x4(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x4,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    0xeac(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <printf@plt>
lea    0xea6(%rip),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"0123456\00"
@.str.1 = [17 x i8] c"[%s] sizeof:%lu\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = alloca i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = load i8*, i8** %2
%5 = call i32 @strncpy(i8* %3, i8* %4, i32 4)
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 4)
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @snprintf(i8* %8, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 4)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"0123456\00"
@.str.1 = [17 x i8] c"[%s] sizeof:%lu\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 4)
%5 = call i32 @snprintf(i8* %2, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 4)
ret i32 0
}