#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*/ ho_strncpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char buf[128] = "12345";
  ho_strncpy(buf, "aaaa", 3);
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
movb   $0x31,-0x90(%rbp)
movb   $0x32,-0x8f(%rbp)
movb   $0x33,-0x8e(%rbp)
movb   $0x34,-0x8d(%rbp)
movb   $0x35,-0x8c(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x3,%edx
call   1050 <ho_strncpy@plt>
lea    -0x90(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x34333231,(%rsp)
movb   $0x35,0x4(%rsp)
lea    0xe9b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1040 <ho_strncpy@plt>
lea    0xe89(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"aaaa\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
store i32 0, i32* %1
%3 = bitcast [128 x i8]* %2 to i8*
%4 = bitcast i8* %3 to [128 x i8]*
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 0
store i8 49, i8* %5
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 1
store i8 50, i8* %6
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 2
store i8 51, i8* %7
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 3
store i8 52, i8* %8
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i32 0, i32 4
store i8 53, i8* %9
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%11 = call i32 @ho_strncpy(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"aaaa\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
store i8 49, i8* %2
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 1
store i8 50, i8* %3
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 2
store i8 51, i8* %4
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 3
store i8 52, i8* %5
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 4
store i8 53, i8* %6
%7 = call i32 @ho_strncpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}