#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*/ getLine(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int stringToInt(char *);
size_t strncmp(char *, char *, int);
int main() {
  char s1[20], s2[20], input[20];
  size_t result;
  int n;
  printf("Enter string s1: ");
  getLine(s1, 20);
  printf("Enter string s2: ");
  getLine(s2, 20);
  printf("Enter number of characters to compare: ");
  getLine(input, 20);
  n = stringToInt(input);
  result = strncmp(s1, s2, n);
  if (result == 0) {
    printf("The first %d characters in the two strings are the same\n", n);
  } else if (result == -1) {
    printf("%s is less than %s\n", s1, s2);
  } else
    printf("%s is greater than %s\n", s1, s2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
lea    -0x60(%rbp),%rdi
call   1050 <stringToInt@plt>
mov    %eax,-0x6c(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x6c(%rbp),%edx
call   1030 <strncmp@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11e4 <main+0xa4>
mov    -0x6c(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xe5>
cmpq   $0xffffffffffffffff,-0x68(%rbp)
jne    120a <main+0xca>
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1220 <main+0xe0>
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xe5>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x14,%esi
call   1060 <getLine@plt>
mov    %rbp,%rdi
call   1050 <stringToInt@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0xffffffffffffffff,%rax
je     11da <main+0x9a>
test   %rax,%rax
jne    11e3 <main+0xa3>
lea    0xe7d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f9 <main+0xb9>
lea    0xea4(%rip),%rdi
jmp    11ea <main+0xaa>
lea    0xeaf(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter string s1: \00"
@.str.1 = [18 x i8] c"Enter string s2: \00"
@.str.2 = [40 x i8] c"Enter number of characters to compare: \00"
@.str.3 = [57 x i8] c"The first %d characters in the two strings are the same\0A\00"
@.str.4 = [20 x i8] c"%s is less than %s\0A\00"
@.str.5 = [23 x i8] c"%s is greater than %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 @getLine(i8* %8, i32 20)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%12 = call i32 @getLine(i8* %11, i32 20)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%15 = call i32 @getLine(i8* %14, i32 20)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%17 = call i32 @stringToInt(i8* %16)
store i32 %17, i32* %6
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = load i32, i32* %6
%21 = call i64 @strncmp(i8* %18, i8* %19, i32 %20)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %39
27: ; preds = %0
%28 = load i64, i64* %5
%29 = icmp eq i64 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %32)
br label %38
34: ; preds = %27
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %35, i8* %36)
br label %38
38: ; preds = %34, %30
br label %39
39: ; preds = %38, %24
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter string s1: \00"
@.str.1 = [18 x i8] c"Enter string s2: \00"
@.str.2 = [40 x i8] c"Enter number of characters to compare: \00"
@.str.3 = [57 x i8] c"The first %d characters in the two strings are the same\0A\00"
@.str.4 = [20 x i8] c"%s is less than %s\0A\00"
@.str.5 = [23 x i8] c"%s is greater than %s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @getLine(i8* %4, i32 20)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @getLine(i8* %5, i32 20)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @getLine(i8* %6, i32 20)
%13 = call i32 @stringToInt(i8* %6)
%14 = call i64 @strncmp(i8* %4, i8* %5, i32 %13)
switch i64 %14, label %19 [
i64 0, label %15
i64 -1, label %17
]
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %21
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %4, i8* %5)
br label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %4, i8* %5)
br label %21
21: ; preds = %17, %19, %15
ret i32 0
}