#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int strncmpm(char *, char *, int);
int main() {
  char str1[100], str2[100];
  int i, n;
  printf("Enter two strings (separated by Enter): ");
  i = 0;
  while ((str1[i++] = getchar()) != '\n')
    ;
  str1[i - 1] = '\0';
  i = 0;
  while ((str2[i++] = getchar()) != '\n')
    ;
  str2[i - 1] = '\0';
  printf("Enter n: ");
  scanf("%d", &n);
  printf("The result of strncmp is: %d\n", strncmpm(str1, str2, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xe4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0xe4(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xe4(%rbp)
movslq %ecx,%rcx
mov    %al,-0x70(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     119a <main+0x5a>
jmp    116a <main+0x2a>
mov    -0xe4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
movl   $0x0,-0xe4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0xe4(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xe4(%rbp)
movslq %ecx,%rcx
mov    %al,-0xe0(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11e7 <main+0xa7>
jmp    11b4 <main+0x74>
mov    -0xe4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe24(%rip),%rdi
lea    -0xe8(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    -0xe8(%rbp),%edx
call   1030 <strncmpm@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xf0,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffffffffffff,%rbx
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x81(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1160 <main+0x20>
mov    %ebx,%eax
movb   $0x0,0x80(%rsp,%rax,1)
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x11(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1190 <main+0x50>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
lea    0x80(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <strncmpm@plt>
lea    0xe50(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Enter two strings (separated by Enter): \00"
@.str.1 = [10 x i8] c"Enter n: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [30 x i8] c"The result of strncmp is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %7
7: ; preds = %15, %0
%8 = call signext i8 (...) @getchar()
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
store i32 %10, i32* %4
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %11
store i8 %8, i8* %12
%13 = sext i8 %8 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %7
br label %7
16: ; preds = %7
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
store i32 0, i32* %4
br label %21
21: ; preds = %29, %16
%22 = call signext i8 (...) @getchar()
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %25
store i8 %22, i8* %26
%27 = sext i8 %22 to i32
%28 = icmp ne i32 %27, 10
br i1 %28, label %29, label %30
29: ; preds = %21
br label %21
30: ; preds = %21
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%39 = load i32, i32* %5
%40 = call i32 @strncmpm(i8* %37, i8* %38, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Enter two strings (separated by Enter): \00"
@.str.1 = [10 x i8] c"Enter n: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [30 x i8] c"The result of strncmp is: %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ %11, %8 ], [ 0, %0 ]
%10 = tail call signext i8 (...) @getchar()
%11 = add nuw i64 %9, 1
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %9
store i8 %10, i8* %12
%13 = icmp eq i8 %10, 10
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = and i64 %9, 4294967295
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %17, %14
%18 = phi i64 [ %20, %17 ], [ 0, %14 ]
%19 = tail call signext i8 (...) @getchar()
%20 = add nuw i64 %18, 1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
store i8 %19, i8* %21
%22 = icmp eq i8 %19, 10
br i1 %22, label %23, label %17
23: ; preds = %17
%24 = and i64 %18, 4294967295
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%28 = load i32, i32* %3
%29 = call i32 @strncmpm(i8* %4, i8* %5, i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %29)
ret i32 0
}