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

/* Variables and functions */
int /*<<< orphan*/ Panic(char *);
int strlcat(char *, char *, int);
int strlcpy(char *, char *, int);
int strlen(char *);
void Check_strlcat(void) {
  char str[5];
  if (strlcpy(str, "12", sizeof(str)) != 2)
    Panic("strlcpy for strlcat");
  if (strlcat(str, "1234567890", sizeof(str)) != 12)
    Panic("strlcat return code");
  if (str[4] != '\0')
    Panic("strlcat NULL byte");
  if (strlen(str) != 4)
    Panic("strlcat string length");
}


x86 assembly (clang, -O0):
<Check_strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x5(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x5,%edx
call   1060 <strlcpy@plt>
cmp    $0x2,%eax
je     1172 <Check_strlcat+0x32>
lea    0xe96(%rip),%rdi
call   1050 <Panic@plt>
lea    -0x5(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x5,%edx
call   1030 <strlcat@plt>
cmp    $0xc,%eax
je     119c <Check_strlcat+0x5c>
lea    0xe8b(%rip),%rdi
call   1050 <Panic@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
je     11b5 <Check_strlcat+0x75>
lea    0xe86(%rip),%rdi
call   1050 <Panic@plt>
lea    -0x5(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
je     11d3 <Check_strlcat+0x93>
lea    0xe7a(%rip),%rdi
call   1050 <Panic@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Check_strlcat>:
push   %rax
lea    0xeb8(%rip),%rsi
lea    0x3(%rsp),%rdi
mov    $0x5,%edx
call   1060 <strlcpy@plt>
cmp    $0x2,%eax
je     1168 <Check_strlcat+0x28>
lea    0xea0(%rip),%rdi
call   1050 <Panic@plt>
lea    0xea8(%rip),%rsi
lea    0x3(%rsp),%rdi
mov    $0x5,%edx
call   1030 <strlcat@plt>
cmp    $0xc,%eax
je     118f <Check_strlcat+0x4f>
lea    0xe98(%rip),%rdi
call   1050 <Panic@plt>
cmpb   $0x0,0x7(%rsp)
je     11a2 <Check_strlcat+0x62>
lea    0xe99(%rip),%rdi
call   1050 <Panic@plt>
lea    0x3(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
je     11bd <Check_strlcat+0x7d>
lea    0xe90(%rip),%rdi
call   1050 <Panic@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"12\00"
@.str.1 = [20 x i8] c"strlcpy for strlcat\00"
@.str.2 = [11 x i8] c"1234567890\00"
@.str.3 = [20 x i8] c"strlcat return code\00"
@.str.4 = [18 x i8] c"strlcat NULL byte\00"
@.str.5 = [22 x i8] c"strlcat string length\00"
define void @Check_strlcat() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlcpy(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
%4 = icmp ne i32 %3, 2
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @Panic(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%9 = call i32 @strlcat(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 5)
%10 = icmp ne i32 %9, 12
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @Panic(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @Panic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = icmp ne i32 %22, 4
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @Panic(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"12\00"
@.str.1 = [20 x i8] c"strlcpy for strlcat\00"
@.str.2 = [11 x i8] c"1234567890\00"
@.str.3 = [20 x i8] c"strlcat return code\00"
@.str.4 = [18 x i8] c"strlcat NULL byte\00"
@.str.5 = [22 x i8] c"strlcat string length\00"
define void @Check_strlcat() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlcpy(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
%4 = icmp eq i32 %3, 2
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @Panic(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @strlcat(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 5)
%9 = icmp eq i32 %8, 12
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @Panic(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @Panic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = call i32 @strlen(i8* %2)
%20 = icmp eq i32 %19, 4
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @Panic(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret void
}