#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 *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void demo_substr(void) {
  char date[] = "March 23, 2016";
  char copy[10];
  strncpy(copy, date + 6, 2);
  copy[2] = '\0';
  printf("date = %s\n", date);
  printf("copy = %s\n", copy);
}


x86 assembly (clang, -O0):
<demo_substr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x7(%rbp)
mov    0xec9(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xec1(%rip),%al
mov    %al,-0x1(%rbp)
lea    -0x19(%rbp),%rdi
lea    -0xf(%rbp),%rsi
add    $0x6,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x17(%rbp)
lea    -0xf(%rbp),%rsi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x19(%rbp),%rsi
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demo_substr>:
push   %rbx
sub    $0x20,%rsp
movabs $0x36313032202c33,%rax
mov    %rax,0x7(%rsp)
movabs $0x333220686372614d,%rax
20 32 33
mov    %rax,(%rsp)
lea    0x6(%rsp),%rsi
lea    0x16(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x18(%rsp)
lea    0xeaa(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.demo_substr.date = [15 x i8] c"March 23, 2016\00"
@.str = [11 x i8] c"date = %s\0A\00"
@.str.1 = [11 x i8] c"copy = %s\0A\00"
define void @demo_substr() {
%1 = alloca [15 x i8]
%2 = alloca [10 x i8]
%3 = bitcast [15 x i8]* %1 to i8*
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds i8, i8* %5, i64 6
%7 = call i32 @strncpy(i8* %4, i8* %6, i32 2)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 0, i8* %8
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %11)
ret void
}

LLVM IR (-O2):
@__const.demo_substr.date = [15 x i8] c"March 23, 2016\00"
@.str = [11 x i8] c"date = %s\0A\00"
@.str.1 = [11 x i8] c"copy = %s\0A\00"
define void @demo_substr() {
%1 = alloca [15 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 6
%6 = call i32 @strncpy(i8* %4, i8* %5, i32 2)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 0, i8* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret void
}