#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 *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int strlen(char *);
int main() {
  char s1[32];
  char s2[32];
  char s3[32];
  sprintf(s2, "1234567890");
  strlcpy(s1, s2, 4);
  strlcpy(s3, s2, strlen(s2));
  printf("s1='%s'\r\ns2='%s'\r\ns3='%s'\r\n", s1, s2, s3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x4,%edx
call   1050 <strlcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1050 <strlcpy@plt>
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
movabs $0x3837363534333231,%rax
36 37 38
mov    %rax,(%rsp)
movl   $0x303938,0x7(%rsp)
lea    0x40(%rsp),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <strlcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <strlcpy@plt>
lea    0xe83(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"1234567890\00"
@.str.1 = [28 x i8] c"s1='%s'\0D\0As2='%s'\0D\0As3='%s'\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = call i32 @strlcpy(i8* %7, i8* %8, i32 4)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @strlcpy(i8* %10, i8* %11, i32 %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"1234567890\00"
@.str.1 = [28 x i8] c"s1='%s'\0D\0As2='%s'\0D\0As3='%s'\0D\0A\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = call i32 @strlcpy(i8* %4, i8* %5, i32 4)
%8 = call i32 @strlen(i8* %5)
%9 = call i32 @strlcpy(i8* %6, i8* %5, i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %5, i8* %6)
ret i32 0
}