#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int scanf(char *, ...);
int /*<<< orphan*/ stdin;
int strncmp(char *, char *, unsigned int);
int main(void) {
  char stringa1[40];
  char stringa2[40];
  int confronto;
  unsigned int numeroCaratteriDaControllare;
  int controlloScanf;
  memset(stringa1, 0, 40);
  memset(stringa2, 0, 40);
  printf("%s", "\nPrego inserire il valore della stringa1: ");
  fgets(stringa1, 40, stdin);
  printf("%s", "\nPrego inserire il valore della stringa2: ");
  fgets(stringa2, 40, stdin);
  printf("%s", "\nPrego inserire il numero di caratteri da confrontare: ");
  do {
    controlloScanf = scanf("%u", &numeroCaratteriDaControllare);
    if (controlloScanf == 0) {
      scanf("%*[^\n]");
      puts("Input errato, inserire un intero: ");
    }
  } while (controlloScanf == 0);
  puts("");
  confronto = strncmp(stringa1, stringa2, numeroCaratteriDaControllare);
  if (confronto == 0) {
    puts("Le stringhe sono della stessa lunghezza");
  } else if (confronto >= 1) {
    puts("La stringa1 e' maggiore della stringa2");
  } else if (confronto <= -1) {
    puts("La stringa2 e' maggiore della stringa1");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xe6a(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0x28,%esi
call   1070 <fgets@plt>
lea    0xe40(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
mov    $0x28,%esi
call   1070 <fgets@plt>
lea    0xe16(%rip),%rdi
lea    0xe68(%rip),%rsi
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x68(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jne    122f <main+0xcf>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
jmp    1234 <main+0xd4>
cmpl   $0x0,-0x6c(%rbp)
je     11f6 <main+0x96>
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
lea    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%edx
call   1030 <strncmp@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    1278 <main+0x118>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
jmp    12b3 <main+0x153>
cmpl   $0x1,-0x64(%rbp)
jl     1293 <main+0x133>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
jmp    12ae <main+0x14e>
cmpl   $0xffffffff,-0x64(%rbp)
jg     12a9 <main+0x149>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
jmp    12ae <main+0x14e>
jmp    12b3 <main+0x153>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0x40(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    0xe56(%rip),%r12
lea    0xe52(%rip),%rsi
mov    %r12,%rdi
call   1060 <printf@plt>
mov    0x2e28(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x28,%esi
call   1080 <fgets@plt>
lea    0xe58(%rip),%rsi
mov    %r12,%rdi
call   1060 <printf@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x28,%esi
call   1080 <fgets@plt>
lea    0xe65(%rip),%rsi
mov    %r12,%rdi
call   1060 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
test   %eax,%eax
jne    1253 <main+0xe3>
lea    0xe7a(%rip),%r14
lea    0xe7a(%rip),%r15
lea    0xe69(%rip),%r12
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
test   %eax,%eax
je     1230 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edx
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <strncmp@plt>
test   %eax,%eax
lea    0xe6d(%rip),%rax
lea    0xe8d(%rip),%rcx
cmovg  %rax,%rcx
lea    0xe33(%rip),%rdi
cmovne %rcx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [43 x i8] c"\0APrego inserire il valore della stringa1: \00"
@stdin = global i32 0
@.str.2 = [43 x i8] c"\0APrego inserire il valore della stringa2: \00"
@.str.3 = [56 x i8] c"\0APrego inserire il numero di caratteri da confrontare: \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [7 x i8] c"%*[^\0A]\00"
@.str.6 = [35 x i8] c"Input errato, inserire un intero: \00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [40 x i8] c"Le stringhe sono della stessa lunghezza\00"
@.str.9 = [39 x i8] c"La stringa1 e' maggiore della stringa2\00"
@.str.10 = [39 x i8] c"La stringa2 e' maggiore della stringa1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 40)
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 40)
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 40, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 40, i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %28, %0
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %27
27: ; preds = %24, %20
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 0
br i1 %30, label %20, label %31
31: ; preds = %28
%32 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0))
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%35 = load i32, i32* %5
%36 = call i32 @strncmp(i8* %33, i8* %34, i32 %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %53
41: ; preds = %31
%42 = load i32, i32* %4
%43 = icmp sge i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0))
br label %52
46: ; preds = %41
%47 = load i32, i32* %4
%48 = icmp sle i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
br label %52
52: ; preds = %51, %44
br label %53
53: ; preds = %52, %39
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [43 x i8] c"\0APrego inserire il valore della stringa1: \00"
@stdin = global i32 0
@.str.2 = [43 x i8] c"\0APrego inserire il valore della stringa2: \00"
@.str.3 = [56 x i8] c"\0APrego inserire il numero di caratteri da confrontare: \00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [7 x i8] c"%*[^\0A]\00"
@.str.6 = [35 x i8] c"Input errato, inserire un intero: \00"
@.str.8 = [40 x i8] c"Le stringhe sono della stessa lunghezza\00"
@.str.9 = [39 x i8] c"La stringa1 e' maggiore della stringa2\00"
@.str.10 = [39 x i8] c"La stringa2 e' maggiore della stringa1\00"
define i32 @main() {
%1 = alloca [40 x i8]
%2 = alloca [40 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = call i32 @memset(i8* %4, i32 0, i32 40)
%8 = call i32 @memset(i8* %5, i32 0, i32 40)
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %4, i32 40, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %5, i32 40, i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %0, %18
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %18, %0
%24 = call i32 @putchar(i32 10)
%25 = load i32, i32* %3
%26 = call i32 @strncmp(i8* %4, i8* %5, i32 %25)
%27 = icmp eq i32 %26, 0
%28 = icmp sgt i32 %26, 0
%29 = select i1 %28, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0)
%30 = select i1 %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %29
%31 = call i32 @puts(i8* dereferenceable(1) %30)
ret i32 0
}