#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 *);
scalar_t__ strncmp(char *, char *, int);
int main(void) {
  char str1[] = "ABCXDEF";
  char str2[] = "ABD";
  char target[] = "ABCXDEG";
  str1[3] = '\0';
  target[3] = '\0';
  if (strncmp(str1, target, 3) == 0) {
    printf("strncmp(str1, target, 3) is match!\n");
  }
  if (strncmp(str2, target, 3) != 0) {
    printf("strncmp(str2, target, 3) is unmatch!\n");
  }
  if (strncmp(str1, target, 6) == 0) {
    printf("strncpm(str1, target, 6) is match!\n");
  }
  if (strncmp(str1, target, 7) == 0) {
    printf("strncpm(str1, target, 7) is match!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x9(%rbp)
movb   $0x0,-0x15(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    117e <main+0x5e>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a6 <main+0x86>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ce <main+0xae>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f6 <main+0xd6>
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movabs $0x46454400434241,%rax
mov    %rax,0x8(%rsp)
movl   $0x444241,0x14(%rsp)
movabs $0x47454400434241,%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    116c <main+0x4c>
lea    0xf04(%rip),%rdi
call   1040 <puts@plt>
lea    0x14(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118f <main+0x6f>
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b2 <main+0x92>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d5 <main+0xb5>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.str1 = [8 x i8] c"ABCXDEF\00"
@__const.main.str2 = [4 x i8] c"ABD\00"
@__const.main.target = [8 x i8] c"ABCXDEG\00"
@.str = [36 x i8] c"strncmp(str1, target, 3) is match!\0A\00"
@.str.1 = [38 x i8] c"strncmp(str2, target, 3) is unmatch!\0A\00"
@.str.2 = [36 x i8] c"strncpm(str1, target, 6) is match!\0A\00"
@.str.3 = [36 x i8] c"strncpm(str1, target, 7) is match!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [4 x i8]
%4 = alloca [8 x i8]
store i32 0, i32* %1
%5 = bitcast [8 x i8]* %2 to i8*
%6 = bitcast [4 x i8]* %3 to i8*
%7 = bitcast [8 x i8]* %4 to i8*
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 0, i8* %8
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 3
store i8 0, i8* %9
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%12 = call i64 @strncmp(i8* %10, i8* %11, i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%19 = call i64 @strncmp(i8* %17, i8* %18, i32 3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%26 = call i64 @strncmp(i8* %24, i8* %25, i32 6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%33 = call i64 @strncmp(i8* %31, i8* %32, i32 7)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
ret i32 0
}

LLVM IR (-O2):
@str = [35 x i8] c"strncpm(str1, target, 7) is match!\00"
@str.4 = [35 x i8] c"strncpm(str1, target, 6) is match!\00"
@str.5 = [37 x i8] c"strncmp(str2, target, 3) is unmatch!\00"
@str.6 = [35 x i8] c"strncmp(str1, target, 3) is match!\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
store i64 19779406734246465, i64* %1
%5 = bitcast i32* %2 to i8*
store i32 4473409, i32* %2
%6 = bitcast i64* %3 to i8*
store i64 20060881710957121, i64* %3
%7 = call i64 @strncmp(i8* %4, i8* %6, i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i64 @strncmp(i8* %5, i8* %6, i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.5, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = call i64 @strncmp(i8* %4, i8* %6, i32 6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = call i64 @strncmp(i8* %4, i8* %6, i32 7)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
ret i32 0
}