#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 *__strncat_chk(char *, char *, int, int);
int /*<<< orphan*/ printf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int test_strncat_chk(void) {
  char dest[32];
  dest[0] = 0;
  do {
    if (!(dest == __strncat_chk(dest, "xyz", 4, sizeof dest))) {
      printf("expression '%s' untrue at %d\n",
             "dest == __strncat_chk(dest, \"xyz\", 4, sizeof dest)", 276);
      return 0;
    }
  } while (0);
  do {
    if (!(strcmp(dest, "xyz") == 0)) {
      printf("expression '%s' untrue at %d\n", "strcmp(dest, \"xyz\") == 0",
             277);
      return 0;
    }
  } while (0);
  do {
    if (!(dest == __strncat_chk(dest, "xyz", 1, sizeof dest))) {
      printf("expression '%s' untrue at %d\n",
             "dest == __strncat_chk(dest, \"xyz\", 1, sizeof dest)", 278);
      return 0;
    }
  } while (0);
  do {
    if (!(strcmp(dest, "xyzx") == 0)) {
      printf("expression '%s' untrue at %d\n", "strcmp(dest, \"xyzx\") == 0",
             279);
      return 0;
    }
  } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<test_strncat_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    0xeb1(%rip),%rsi
mov    $0x4,%edx
mov    $0x20,%ecx
call   1050 <__strncat_chk@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     1192 <test_strncat_chk+0x62>
lea    0xe8f(%rip),%rdi
lea    0xea6(%rip),%rsi
mov    $0x114,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <test_strncat_chk+0x15e>
jmp    1197 <test_strncat_chk+0x67>
jmp    119c <test_strncat_chk+0x6c>
lea    -0x30(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11da <test_strncat_chk+0xaa>
lea    0xe47(%rip),%rdi
lea    0xe91(%rip),%rsi
mov    $0x115,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <test_strncat_chk+0x15e>
jmp    11df <test_strncat_chk+0xaf>
jmp    11e4 <test_strncat_chk+0xb4>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x1,%edx
mov    $0x20,%ecx
call   1050 <__strncat_chk@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     123a <test_strncat_chk+0x10a>
lea    0xde7(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x116,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <test_strncat_chk+0x15e>
jmp    123f <test_strncat_chk+0x10f>
jmp    1244 <test_strncat_chk+0x114>
lea    -0x30(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1282 <test_strncat_chk+0x152>
lea    0xd9f(%rip),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x117,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <test_strncat_chk+0x15e>
jmp    1287 <test_strncat_chk+0x157>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strncat_chk>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movb   $0x0,(%rsp)
lea    0xebe(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
mov    $0x20,%ecx
call   1050 <__strncat_chk@plt>
cmp    %rax,%rbx
je     1174 <test_strncat_chk+0x44>
lea    0xea1(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x114,%edx
jmp    11ff <test_strncat_chk+0xcf>
lea    0xe85(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a0 <test_strncat_chk+0x70>
lea    0xe72(%rip),%rdi
lea    0xebc(%rip),%rsi
mov    $0x115,%edx
jmp    11ff <test_strncat_chk+0xcf>
lea    0xe59(%rip),%rsi
mov    $0x1,%ebx
mov    %r14,%rdi
mov    $0x1,%edx
mov    $0x20,%ecx
call   1050 <__strncat_chk@plt>
cmp    %rax,%r14
je     11d8 <test_strncat_chk+0xa8>
lea    0xe3a(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x116,%edx
jmp    11ff <test_strncat_chk+0xcf>
lea    0xec2(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1206 <test_strncat_chk+0xd6>
lea    0xe11(%rip),%rdi
lea    0xeac(%rip),%rsi
mov    $0x117,%edx
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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 = [51 x i8] c"dest == __strncat_chk(dest, \22xyz\22, 4, sizeof dest)\00"
@.str.3 = [25 x i8] c"strcmp(dest, \22xyz\22) == 0\00"
@.str.4 = [51 x i8] c"dest == __strncat_chk(dest, \22xyz\22, 1, sizeof dest)\00"
@.str.5 = [5 x i8] c"xyzx\00"
@.str.6 = [26 x i8] c"strcmp(dest, \22xyzx\22) == 0\00"
define i32 @test_strncat_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* @__strncat_chk(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4, 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 ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 276)
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 277)
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* @__strncat_chk(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1, 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 ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 278)
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 ([5 x i8], [5 x i8]* @.str.5, 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 ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 279)
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 = [51 x i8] c"dest == __strncat_chk(dest, \22xyz\22, 4, sizeof dest)\00"
@.str.3 = [25 x i8] c"strcmp(dest, \22xyz\22) == 0\00"
@.str.4 = [51 x i8] c"dest == __strncat_chk(dest, \22xyz\22, 1, sizeof dest)\00"
@.str.5 = [5 x i8] c"xyzx\00"
@.str.6 = [26 x i8] c"strcmp(dest, \22xyzx\22) == 0\00"
define i32 @test_strncat_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* @__strncat_chk(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4, 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 ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 276)
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 277)
br label %22
12: ; preds = %7
%13 = call i8* @__strncat_chk(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1, 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 ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 278)
br label %22
17: ; preds = %12
%18 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, 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 ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 279)
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
}