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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ strcmp(char *, char *);
int strlcat(char *, char *, int);
int strlcpy(char *, char *, int);
int main(void) {
  char buf[16];
  int i;
  buf[0] = 0;
  i = strlcpy(buf, "Foo", sizeof(buf));
  assert(i == 3);
  buf[0] = 0;
  i = strlcpy(buf, "This is a long string", sizeof(buf));
  assert(i >= sizeof(buf));
  assert(!strcmp(buf, "This is a long "));
  buf[0] = 0;
  i = strlcat(buf, "This is", sizeof(buf));
  assert(i == 7);
  assert(!strcmp(buf, "This is"));
  i = strlcat(buf, " a ", sizeof(buf));
  assert(i == 10);
  assert(!strcmp(buf, "This is a "));
  i = strlcat(buf, "long string", sizeof(buf));
  assert(i >= sizeof(buf));
  assert(!strcmp(buf, "This is a long "));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x10,%edx
call   1060 <strlcpy@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x10,%edx
call   1060 <strlcpy@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x10,%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x10,%edx
call   1030 <strlcat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x10,%edx
call   1030 <strlcat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xd9a(%rip),%rsi
mov    $0x10,%edx
call   1030 <strlcat@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x10,%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,(%rsp)
lea    0xed0(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x10,%edx
call   1050 <strlcpy@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1040 <assert@plt>
movb   $0x0,(%rsp)
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1050 <strlcpy@plt>
xor    %edi,%edi
cmp    $0x10,%eax
setae  %dil
call   1040 <assert@plt>
movdqa (%rsp),%xmm0
pcmpeqb 0xe6f(%rip),%xmm0
pmovmskb %xmm0,%eax
xor    %edi,%edi
cmp    $0xffff,%eax
sete   %dil
call   1040 <assert@plt>
movb   $0x0,(%rsp)
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strlcat@plt>
xor    %edi,%edi
cmp    $0x7,%eax
sete   %dil
call   1040 <assert@plt>
movabs $0x73692073696854,%rax
xor    %edi,%edi
cmp    %rax,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strlcat@plt>
xor    %edi,%edi
cmp    $0xa,%eax
sete   %dil
call   1040 <assert@plt>
movabs $0x2073692073696854,%rax
69 73 20
xor    (%rsp),%rax
movabs $0x20612073692073,%rcx
xor    0x3(%rsp),%rcx
xor    %edi,%edi
or     %rax,%rcx
sete   %dil
call   1040 <assert@plt>
lea    0xde6(%rip),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strlcat@plt>
xor    %edi,%edi
cmp    $0x10,%eax
setae  %dil
call   1040 <assert@plt>
movdqa 0xda5(%rip),%xmm0
pcmpeqb (%rsp),%xmm0
pmovmskb %xmm0,%eax
xor    %edi,%edi
cmp    $0xffff,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"Foo\00"
@.str.1 = [22 x i8] c"This is a long string\00"
@.str.2 = [16 x i8] c"This is a long \00"
@.str.3 = [8 x i8] c"This is\00"
@.str.4 = [4 x i8] c" a \00"
@.str.5 = [11 x i8] c"This is a \00"
@.str.6 = [12 x i8] c"long string\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
store i8 0, i8* %4
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = call i32 @strlcpy(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 3
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlcpy(i8* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 16)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = icmp uge i64 %15, 16
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
store i8 0, i8* %25
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%27 = call i32 @strlcat(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 16)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 7
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%39 = call i32 @strlcat(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 16)
store i32 %39, i32* %3
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 10
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%51 = call i32 @strlcat(i8* %50, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 16)
store i32 %51, i32* %3
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = icmp uge i64 %53, 16
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%58 = call i32 @strcmp(i8* %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"Foo\00"
@.str.1 = [22 x i8] c"This is a long string\00"
@.str.2 = [16 x i8] c"This is a long \00"
@.str.3 = [8 x i8] c"This is\00"
@.str.4 = [4 x i8] c" a \00"
@.str.5 = [11 x i8] c"This is a \00"
@.str.6 = [12 x i8] c"long string\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
%3 = call i32 @strlcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16)
%4 = icmp eq i32 %3, 3
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
store i8 0, i8* %2
%7 = call i32 @strlcpy(i8* %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 16)
%8 = icmp ugt i32 %7, 15
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @bcmp(i8* dereferenceable(16) %2, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 16)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i8 0, i8* %2
%15 = call i32 @strlcat(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 16)
%16 = icmp eq i32 %15, 7
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = bitcast [16 x i8]* %1 to i64*
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 32485210417883220
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @strlcat(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 16)
%25 = icmp eq i32 %24, 10
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @bcmp(i8* dereferenceable(11) %2, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 11)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @strlcat(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 16)
%33 = icmp ugt i32 %32, 15
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @bcmp(i8* dereferenceable(16) %2, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 16)
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
ret i32 0
}