#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 *, ...);
char *strcat(char *, char *);
char *strncat(char *, char *, int);
void fig08_16() {
  char s1[20] = "Happy ";
  char s2[] = "New Year ";
  char s3[40] = "";
  printf("s1 = %s\ns2 = %s\n", s1, s2);
  printf("strcat( s1, s2 ) = %s\n", strcat(s1, s2));
  printf("strncat( s3, s1, 6 ) = %s\n", strncat(s3, s1, 6));
  printf("strcat( s3, s1 ) = %s\n", strcat(s3, s1));
}


x86 assembly (clang, -O0):
<fig08_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x2a(%rbp)
mov    0xea3(%rip),%ax
mov    %ax,-0x22(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rsi
lea    -0x2a(%rbp),%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x6,%edx
call   1050 <strncat@plt>
mov    %rax,%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_16>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
movabs $0x726165592077654e,%rax
65 61 72
mov    %rax,(%rsp)
movw   $0x20,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movq   $0x0,0x50(%rsp)
lea    0xea1(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1040 <strncat@plt>
lea    0xe7c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
lea    0xe7b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fig08_16.s1 = [20 x i8] c"Happy \00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.fig08_16.s2 = [10 x i8] c"New Year \00"
@.str = [17 x i8] c"s1 = %s\0As2 = %s\0A\00"
@.str.1 = [23 x i8] c"strcat( s1, s2 ) = %s\0A\00"
@.str.2 = [27 x i8] c"strncat( s3, s1, 6 ) = %s\0A\00"
@.str.3 = [23 x i8] c"strcat( s3, s1 ) = %s\0A\00"
define void @fig08_16() {
%1 = alloca [20 x i8]
%2 = alloca [10 x i8]
%3 = alloca [40 x i8]
%4 = bitcast [20 x i8]* %1 to i8*
%5 = bitcast [10 x i8]* %2 to i8*
%6 = bitcast [40 x i8]* %3 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i8* @strcat(i8* %10, i8* %11)
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%16 = call i8* @strncat(i8* %14, i8* %15, i32 6)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%20 = call i8* @strcat(i8* %18, i8* %19)
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %20)
ret void
}

LLVM IR (-O2):
@__const.fig08_16.s1 = [20 x i8] c"Happy \00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.fig08_16.s2 = [10 x i8] c"New Year \00"
@.str = [17 x i8] c"s1 = %s\0As2 = %s\0A\00"
@.str.1 = [23 x i8] c"strcat( s1, s2 ) = %s\0A\00"
@.str.2 = [27 x i8] c"strncat( s3, s1, 6 ) = %s\0A\00"
@.str.3 = [23 x i8] c"strcat( s3, s1 ) = %s\0A\00"
define void @fig08_16() {
%1 = alloca [20 x i8]
%2 = alloca [10 x i8]
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %5)
%8 = call i8* @strcat(i8* %4, i8* %5)
%9 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = call i8* @strncat(i8* %6, i8* %4, i32 6)
%11 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i8* @strcat(i8* %6, i8* %4)
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %6)
ret void
}