#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*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void fig08_15() {
  char x[] = "Happy Birthday to You";
  char y[25];
  char z[15];
  printf("%s%s\n%s%s\n", "The string in array x is: ", x,
         "The string in array y is: ", strcpy(y, x));
  strncpy(z, x, 15 - 1);
  z[15 - 1] = '\0';
  printf("The string in array z is: %s\n", z);
}


x86 assembly (clang, -O0):
<fig08_15>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xeb6(%rip),%ax
mov    %ax,-0xc(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x58(%rbp),%rdx
mov    %eax,%r8d
lea    0xe91(%rip),%rdi
lea    0xe95(%rip),%rsi
lea    0xea9(%rip),%rcx
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4f(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x41(%rbp)
lea    -0x4f(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_15>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x756f59206f7420,%rax
mov    %rax,0xe(%rsp)
lea    0x30(%rsp),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xeae(%rip),%rdi
lea    0xeb2(%rip),%rsi
lea    0xec6(%rip),%rcx
mov    %r14,%rdx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x21(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2f(%rsp)
lea    0xeb3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fig08_15.x = [22 x i8] c"Happy Birthday to You\00"
@.str = [11 x i8] c"%s%s\0A%s%s\0A\00"
@.str.1 = [27 x i8] c"The string in array x is: \00"
@.str.2 = [27 x i8] c"The string in array y is: \00"
@.str.3 = [30 x i8] c"The string in array z is: %s\0A\00"
define void @fig08_15() {
%1 = alloca [22 x i8]
%2 = alloca [25 x i8]
%3 = alloca [15 x i8]
%4 = bitcast [22 x i8]* %1 to i8*
%5 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 0
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 0
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 14)
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 14
store i8 0, i8* %13
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %14)
ret void
}

LLVM IR (-O2):
@__const.fig08_15.x = [22 x i8] c"Happy Birthday to You\00"
@.str = [11 x i8] c"%s%s\0A%s%s\0A\00"
@.str.1 = [27 x i8] c"The string in array x is: \00"
@.str.2 = [27 x i8] c"The string in array y is: \00"
@.str.3 = [30 x i8] c"The string in array z is: %s\0A\00"
define void @fig08_15() {
%1 = alloca [22 x i8]
%2 = alloca [25 x i8]
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [22 x i8], [22 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcpy(i8* %5, i8* %4)
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 @strncpy(i8* %6, i8* %4, i32 14)
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 14
store i8 0, i8* %10
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %6)
ret void
}