#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 */
char *__strcat_chk(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int test_strcat_chk(void) {
  char dest[32];
  dest[0] = 0;
  do {
    if (!(dest == __strcat_chk(dest, "xyz", sizeof dest))) {
      printf("expression '%s' untrue at %d\n",
             "dest == __strcat_chk(dest, \"xyz\", sizeof dest)", 202);
      return 0;
    }
  } while (0);
  do {
    if (!(strcmp(dest, "xyz") == 0)) {
      printf("expression '%s' untrue at %d\n", "strcmp(dest, \"xyz\") == 0",
             203);
      return 0;
    }
  } while (0);
  do {
    if (!(dest == __strcat_chk(dest, "xyz", sizeof dest))) {
      printf("expression '%s' untrue at %d\n",
             "dest == __strcat_chk(dest, \"xyz\", sizeof dest)", 204);
      return 0;
    }
  } while (0);
  do {
    if (!(strcmp(dest, "xyzxyz") == 0)) {
      printf("expression '%s' untrue at %d\n", "strcmp(dest, \"xyzxyz\") == 0",
             205);
      return 0;
    }
  } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<test_strcat_chk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movb   $0x0,-0x30(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xf1a(%rip),%rsi
mov    $0x20,%edx
call   1030 <__strcat_chk@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     118d <test_strcat_chk+0x5d>
lea    0xe90(%rip),%rdi
lea    0xea7(%rip),%rsi
mov    $0xca,%edx
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <test_strcat_chk+0x154>
jmp    1192 <test_strcat_chk+0x62>
jmp    1197 <test_strcat_chk+0x67>
lea    -0x30(%rbp),%rdi
lea    0xec7(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d5 <test_strcat_chk+0xa5>
lea    0xe48(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0xcb,%edx
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <test_strcat_chk+0x154>
jmp    11da <test_strcat_chk+0xaa>
jmp    11df <test_strcat_chk+0xaf>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x20,%edx
call   1030 <__strcat_chk@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     1230 <test_strcat_chk+0x100>
lea    0xded(%rip),%rdi
lea    0xe04(%rip),%rsi
mov    $0xcc,%edx
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <test_strcat_chk+0x154>
jmp    1235 <test_strcat_chk+0x105>
jmp    123a <test_strcat_chk+0x10a>
lea    -0x30(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1278 <test_strcat_chk+0x148>
lea    0xda5(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0xcd,%edx
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <test_strcat_chk+0x154>
jmp    127d <test_strcat_chk+0x14d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcat_chk>:
push   %rbx
sub    $0x20,%rsp
movb   $0x0,(%rsp)
lea    0xf29(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%edx
call   1030 <__strcat_chk@plt>
cmp    %rax,%rbx
je     116d <test_strcat_chk+0x3d>
lea    0xea4(%rip),%rdi
lea    0xebb(%rip),%rsi
mov    $0xca,%edx
jmp    11ee <test_strcat_chk+0xbe>
lea    0xef5(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1199 <test_strcat_chk+0x69>
lea    0xe75(%rip),%rdi
lea    0xebb(%rip),%rsi
mov    $0xcb,%edx
jmp    11ee <test_strcat_chk+0xbe>
lea    0xec9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x20,%edx
call   1030 <__strcat_chk@plt>
cmp    %rax,%rbx
je     11c7 <test_strcat_chk+0x97>
lea    0xe47(%rip),%rdi
lea    0xe5e(%rip),%rsi
mov    $0xcc,%edx
jmp    11ee <test_strcat_chk+0xbe>
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fb <test_strcat_chk+0xcb>
lea    0xe1e(%rip),%rdi
lea    0xe84(%rip),%rsi
mov    $0xcd,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    $0x1,%eax
jmp    11f5 <test_strcat_chk+0xc5>

LLVM IR (-O0):
@.str = [4 x i8] c"xyz\00"
@.str.1 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.2 = [47 x i8] c"dest == __strcat_chk(dest, \22xyz\22, sizeof dest)\00"
@.str.3 = [25 x i8] c"strcmp(dest, \22xyz\22) == 0\00"
@.str.4 = [7 x i8] c"xyzxyz\00"
@.str.5 = [28 x i8] c"strcmp(dest, \22xyzxyz\22) == 0\00"
define i32 @test_strcat_chk() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
br label %4
4: ; preds = %0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = call i8* @__strcat_chk(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 32)
%8 = icmp eq i8* %5, %7
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 202)
store i32 0, i32* %1
br label %38
11: ; preds = %4
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 203)
store i32 0, i32* %1
br label %38
19: ; preds = %13
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%24 = call i8* @__strcat_chk(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 32)
%25 = icmp eq i8* %22, %24
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 204)
store i32 0, i32* %1
br label %38
28: ; preds = %21
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 205)
store i32 0, i32* %1
br label %38
36: ; preds = %30
br label %37
37: ; preds = %36
store i32 1, i32* %1
br label %38
38: ; preds = %37, %34, %26, %17, %9
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"xyz\00"
@.str.1 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.2 = [47 x i8] c"dest == __strcat_chk(dest, \22xyz\22, sizeof dest)\00"
@.str.3 = [25 x i8] c"strcmp(dest, \22xyz\22) == 0\00"
@.str.4 = [7 x i8] c"xyzxyz\00"
@.str.5 = [28 x i8] c"strcmp(dest, \22xyzxyz\22) == 0\00"
define i32 @test_strcat_chk() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
%3 = call i8* @__strcat_chk(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 32)
%4 = icmp eq i8* %2, %3
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 202)
br label %22
7: ; preds = %0
%8 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 203)
br label %22
12: ; preds = %7
%13 = call i8* @__strcat_chk(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 32)
%14 = icmp eq i8* %2, %13
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 204)
br label %22
17: ; preds = %12
%18 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 205)
br label %22
22: ; preds = %17, %20, %15, %10, %5
%23 = phi i32 [ 0, %20 ], [ 0, %15 ], [ 0, %10 ], [ 0, %5 ], [ 1, %17 ]
ret i32 %23
}