#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*/ my_printf(char *, char, char);
int /*<<< orphan*/ my_puts(char *);
int my_strncmp(char *s1, char *s2, int n) {
  int i = 0;
  my_puts("\n");
  while (s1[i] == s2[i]) {
    my_printf("s1 : %c\ns2 : %c\n", s1[i], s2[i]);
    i++;
  }
  return i - n;
}


x86 assembly (clang, -O0):
<my_strncmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xece(%rip),%rdi
call   1030 <my_puts@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    119a <my_strncmp+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe80(%rip),%rdi
movsbl %dl,%esi
movsbl (%rax,%rcx,1),%edx
call   1040 <my_printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1146 <my_strncmp+0x26>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strncmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xed7(%rip),%rdi
call   1030 <my_puts@plt>
mov    0x0(%rbp),%cl
xor    %eax,%eax
cmp    (%r12),%cl
jne    1180 <my_strncmp+0x60>
xor    %eax,%eax
lea    0xeaf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
movsbl %cl,%edx
mov    %r15,%rdi
mov    %edx,%esi
call   1040 <my_printf@plt>
lea    0x1(%rbx),%rax
movzbl 0x1(%rbp,%rbx,1),%ecx
cmp    0x1(%r12,%rbx,1),%cl
je     1160 <my_strncmp+0x40>
sub    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [17 x i8] c"s1 : %c\0As2 : %c\0A\00"
define i32 @my_strncmp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = call i32 @my_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %23, %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %15, %21
br i1 %22, label %23, label %37
23: ; preds = %9
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @my_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 signext %28, i8 signext %33)
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %9
37: ; preds = %9
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = sub nsw i32 %38, %39
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [17 x i8] c"s1 : %c\0As2 : %c\0A\00"
define i32 @my_strncmp(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @my_puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = load i8, i8* %0
%6 = load i8, i8* %1
%7 = icmp eq i8 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %3, %8
%9 = phi i64 [ %12, %8 ], [ 0, %3 ]
%10 = phi i8 [ %14, %8 ], [ %5, %3 ]
%11 = tail call i32 @my_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8 signext %10, i8 signext %10)
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %1, i64 %12
%16 = load i8, i8* %15
%17 = icmp eq i8 %14, %16
br i1 %17, label %8, label %18
18: ; preds = %8
%19 = trunc i64 %12 to i32
br label %20
20: ; preds = %18, %3
%21 = phi i32 [ 0, %3 ], [ %19, %18 ]
%22 = sub nsw i32 %21, %2
ret i32 %22
}