#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 */
scalar_t__ calloc(unsigned char, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned char);
void fun() {
  unsigned char str_len = 6;
  unsigned char fmt_len = 2;
  char str_chars[6] = {'h', 'e', 'l', 'l', 'o', '\n'};
  char fmt_chars[2] = {'%', 's'};
  char *str = (char *)calloc(str_len, sizeof(char));
  char *fmt = (char *)calloc(fmt_len, sizeof(char));
  strncpy(str, str_chars, str_len);
  strncpy(fmt, fmt_chars, fmt_len);
  printf(fmt, str);
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x6,-0x1(%rbp)
movb   $0x2,-0x2(%rbp)
mov    0xeba(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x4(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0xa(%rbp)
mov    $0x1,%esi
movzbl -0x1(%rbp),%edi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%esi
movzbl -0x2(%rbp),%edi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
movzbl -0x1(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0xa(%rbp),%rsi
movzbl -0x2(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movw   $0xa6f,0x14(%rsp)
movl   $0x6c6c6568,0x10(%rsp)
6c
movw   $0x7325,0xe(%rsp)
mov    $0x6,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fun.str_chars = [6 x i8] c"hello\0A"
@__const.fun.fmt_chars = [2 x i8] c"%s"
define void @fun() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca [6 x i8]
%4 = alloca [2 x i8]
%5 = alloca i8*
%6 = alloca i8*
store i8 6, i8* %1
store i8 2, i8* %2
%7 = bitcast [6 x i8]* %3 to i8*
%8 = bitcast [2 x i8]* %4 to i8*
%9 = load i8, i8* %1
%10 = call i64 @calloc(i8 zeroext %9, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8, i8* %2
%13 = call i64 @calloc(i8 zeroext %12, i32 1)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%17 = load i8, i8* %1
%18 = call i32 @strncpy(i8* %15, i8* %16, i8 zeroext %17)
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%21 = load i8, i8* %2
%22 = call i32 @strncpy(i8* %19, i8* %20, i8 zeroext %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = call i32 @printf(i8* %23, i8* %24)
ret void
}

LLVM IR (-O2):
@__const.fun.str_chars = [6 x i8] c"hello\0A"
define void @fun() {
%1 = alloca [6 x i8]
%2 = alloca i16
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%4 = bitcast i16* %2 to i8*
store i16 29477, i16* %2
%5 = tail call i64 @calloc(i8 zeroext 6, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @calloc(i8 zeroext 2, i32 1)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @strncpy(i8* %6, i8* %3, i8 zeroext 6)
%10 = call i32 @strncpy(i8* %8, i8* %4, i8 zeroext 2)
%11 = call i32 @printf(i8* %8, i8* %6)
ret void
}