#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 test_strncmp(void) {
  printf("\tstrncmp");
  if (strncmp("abcdefg", "abcdefg", 7) != 0)
    return 1;
  if (strncmp("abcdefg", "abcdef", 7) <= 0)
    return 1;
  if (strncmp("abcdef", "abcdefg", 7) >= 0)
    return 1;
  if (strncmp("abcdefg", "abcdeff", 7) <= 0)
    return 1;
  if (strncmp("abcdeff", "abcdefg", 7) >= 0)
    return 1;
  if (strncmp("abcdeff", "abcdefg", 6) != 0)
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
lea    0xece(%rip),%rsi
mov    $0x7,%edx
mov    %rsi,%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     115e <test_strncmp+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xea4(%rip),%rdi
lea    0xea5(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jg     118c <test_strncmp+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xe7e(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jl     11ba <test_strncmp+0x9a>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xe48(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jg     11e8 <test_strncmp+0xc8>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xe29(%rip),%rdi
lea    0xe13(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jl     1216 <test_strncmp+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xdfb(%rip),%rdi
lea    0xde5(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1244 <test_strncmp+0x124>
movl   $0x1,-0x4(%rbp)
jmp    1257 <test_strncmp+0x137>
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strncmp>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
mov    %rdi,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1202 <test_strncmp+0xd2>
lea    0xea3(%rip),%rdi
lea    0xea4(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jle    1202 <test_strncmp+0xd2>
lea    0xe8a(%rip),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jns    1202 <test_strncmp+0xd2>
lea    0xe65(%rip),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jle    1202 <test_strncmp+0xd2>
lea    0xe57(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jns    1202 <test_strncmp+0xd2>
lea    0xe3a(%rip),%rdi
lea    0xe24(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1202 <test_strncmp+0xd2>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\09strncmp\00"
@.str.1 = [8 x i8] c"abcdefg\00"
@.str.2 = [7 x i8] c"abcdef\00"
@.str.3 = [8 x i8] c"abcdeff\00"
@.str.4 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_strncmp() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %0
store i32 1, i32* %1
br label %28
6: ; preds = %0
%7 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 7)
%8 = icmp sle i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
store i32 1, i32* %1
br label %28
10: ; preds = %6
%11 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%12 = icmp sge i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %1
br label %28
14: ; preds = %10
%15 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%16 = icmp sle i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %1
br label %28
18: ; preds = %14
%19 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%20 = icmp sge i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %1
br label %28
22: ; preds = %18
%23 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 6)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %1
br label %28
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %26, %25, %21, %17, %13, %9, %5
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"\09strncmp\00"
@.str.1 = [8 x i8] c"abcdefg\00"
@.str.2 = [7 x i8] c"abcdef\00"
@.str.3 = [8 x i8] c"abcdeff\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_strncmp() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %21
4: ; preds = %0
%5 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 7)
%6 = icmp slt i64 %5, 1
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %21, label %10
10: ; preds = %7
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%12 = icmp slt i64 %11, 1
br i1 %12, label %21, label %13
13: ; preds = %10
%14 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %16, %13, %10, %7, %4, %0, %19
%22 = phi i32 [ 0, %19 ], [ 1, %0 ], [ 1, %4 ], [ 1, %7 ], [ 1, %10 ], [ 1, %13 ], [ 1, %16 ]
ret i32 %22
}