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

/* Variables and functions */
scalar_t__ malloc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy_s(char *, int, char *);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  char s1[] = "012345678";
  char s2[] = "0123456789";
  char *dest;
  int i;
  strcpy_s(s1, sizeof(s2), s2);
  dest = (char *)malloc(strlen(s1));
  for (i = 1; i <= 11; i++) {
    dest[i] = s1[i];
  }
  dest[i] = '\0';
  printf("dest = %s", dest);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xea7(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x19(%rbp)
mov    0xe9b(%rip),%ax
mov    %ax,-0x11(%rbp)
mov    0xe93(%rip),%al
mov    %al,-0xf(%rbp)
lea    -0xe(%rbp),%rdi
lea    -0x19(%rbp),%rdx
mov    $0xb,%esi
call   1060 <strcpy_s@plt>
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0xb,-0x2c(%rbp)
jg     11dc <main+0x9c>
movslq -0x2c(%rbp),%rax
mov    -0xe(%rbp,%rax,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b1 <main+0x71>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,(%rsp)
movw   $0x38,0x8(%rsp)
mov    %rax,0x10(%rsp)
movl   $0x393837,0x17(%rsp)
mov    %rsp,%rbx
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1060 <strcpy_s@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    0x1(%rsp),%rcx
mov    %rcx,0x1(%rax)
mov    0x8(%rsp),%ecx
mov    %ecx,0x8(%rax)
movb   $0x0,0xc(%rax)
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.s1 = [10 x i8] c"012345678\00"
@__const.main.s2 = [11 x i8] c"0123456789\00"
@.str = [10 x i8] c"dest = %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [11 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [10 x i8]* %2 to i8*
%7 = bitcast [11 x i8]* %3 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%10 = call i32 @strcpy_s(i8* %8, i32 11, i8* %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
store i32 1, i32* %5
br label %15
15: ; preds = %27, %0
%16 = load i32, i32* %5
%17 = icmp sle i32 %16, 11
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %18
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %15
30: ; preds = %15
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %4
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@__const.main.s1 = [10 x i8] c"012345678\00"
@__const.main.s2 = [11 x i8] c"0123456789\00"
@.str = [10 x i8] c"dest = %s\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy_s(i8* %3, i32 11, i8* %4)
%6 = call i32 @strlen(i8* %3)
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = getelementptr i8, i8* %8, i64 1
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 1
%11 = getelementptr inbounds i8, i8* %8, i64 12
store i8 0, i8* %11
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
ret i32 0
}