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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void string2() {
  char str1[6] = "hello";
  char *str2 = malloc(6);
  char *str3 = malloc(sizeof(str1) + 1);
  strcpy(str3, str1);
  printf("%s : %s\n", str1, str3);
  free(str2);
  str2 = NULL;
  free(str3);
  str3 = NULL;
}


x86 assembly (clang, -O0):
<string2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xeb2(%rip),%eax
mov    %eax,-0x6(%rbp)
mov    0xeac(%rip),%ax
mov    %ax,-0x2(%rbp)
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x7,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x6(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x6(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string2>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0x6f,0xc(%rsp)
movl   $0x6c6c6568,0x8(%rsp)
6c
mov    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x7,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe7d(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.string2.str1 = [6 x i8] c"hello\00"
@.str = [9 x i8] c"%s : %s\0A\00"
define void @string2() {
%1 = alloca [6 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast [6 x i8]* %1 to i8*
%5 = call i8* @malloc(i32 6)
store i8* %5, i8** %2
%6 = call i8* @malloc(i32 7)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
store i8* null, i8** %2
%15 = load i8*, i8** %3
%16 = call i32 @free(i8* %15)
store i8* null, i8** %3
ret void
}

LLVM IR (-O2):
@__const.string2.str1 = [6 x i8] c"hello\00"
@.str = [9 x i8] c"%s : %s\0A\00"
define void @string2() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%4 = tail call dereferenceable_or_null(7) i8* @malloc(i32 7)
%5 = call i32 @strcpy(i8* %4, i8* %2)
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %4)
%7 = call i32 @free(i8* %3)
%8 = call i32 @free(i8* %4)
ret void
}