#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*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int main() {
  char *s = "abcdefghijklmn";
  char a[5] = "";
  strncat(a, s, 6);
  printf("%s len %d\n", a, strlen(a));
  printf("len %d\n", strlen(a));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x15(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    -0x15(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x6,%edx
call   1060 <strncat@plt>
lea    -0x15(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x15(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x15(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xeb7(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x6,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"abcdefghijklmn\00"
@.str.1 = [11 x i8] c"%s len %d\0A\00"
@.str.2 = [8 x i8] c"len %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [5 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = bitcast [5 x i8]* %3 to i8*
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @strncat(i8* %5, i8* %6, i32 6)
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %10)
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"abcdefghijklmn\00"
@.str.1 = [11 x i8] c"%s len %d\0A\00"
@.str.2 = [8 x i8] c"len %d\0A\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @strncat(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 6)
%4 = call i32 @strlen(i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %4)
%6 = call i32 @strlen(i8* %2)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %6)
ret i32 0
}