#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ tolower(char);
int main() {
  int flag = 1, diff = 0;
  char c, c2;
  FILE *dat1, *dat2;
  if ((dat1 = fopen("dat1.txt", "r")) == NULL) {
    printf("I can't open it sorry!");
    return -1;
  }
  if ((dat2 = fopen("dat2.txt", "r")) == NULL) {
    printf("I can't open it sorry!");
    return -1;
  }
  while (((c = fgetc(dat1)) != EOF) && ((c2 = fgetc(dat2)) != EOF)) {
    if (tolower(c) != tolower(c2)) {
      flag = 0;
      diff++;
    }
  }
  if (flag)
    printf("Both files contain the same content!\n");
  else
    printf("The files are not the same!. Total differences found: %d\n", diff);
  fclose(dat1);
  fclose(dat2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a8 <main+0x58>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c1 <main+0x171>
lea    0xe73(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e3 <main+0x93>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c1 <main+0x171>
jmp    11e8 <main+0x98>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%ecx
mov    0x2dea(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
je     122f <main+0xdf>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0xe(%rbp)
movsbl %al,%eax
mov    0x2dc4(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    123f <main+0xef>
jmp    127a <main+0x12a>
movsbl -0xd(%rbp),%edi
call   1060 <tolower@plt>
mov    %rax,-0x30(%rbp)
movsbl -0xe(%rbp),%edi
call   1060 <tolower@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     1275 <main+0x125>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e8 <main+0x98>
cmpl   $0x0,-0x8(%rbp)
je     1297 <main+0x147>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a8 <main+0x158>
mov    -0xc(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1229 <main+0xc9>
mov    %rax,%r15
lea    0xe91(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1229 <main+0xc9>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2e2f(%rip),%r14
cmp    (%r14),%al
je     121b <main+0xbb>
mov    %eax,%r12d
mov    $0x1,%ebp
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    (%rsp),%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
je     1217 <main+0xb7>
mov    %eax,%ebx
movsbl %r12b,%edi
call   1070 <tolower@plt>
mov    %rax,%r12
movsbl %bl,%edi
call   1070 <tolower@plt>
xor    %ecx,%ecx
cmp    %rax,%r12
setne  %cl
mov    $0x0,%eax
cmovne %eax,%ebp
add    %ecx,%r13d
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r12d
cmp    (%r14),%al
jne    11d0 <main+0x70>
test   %ebp,%ebp
je     123e <main+0xde>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
jmp    124f <main+0xef>
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    1262 <main+0x102>
lea    0xde6(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"dat1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"I can't open it sorry!\00"
@.str.3 = [9 x i8] c"dat2.txt\00"
@EOF = global i8 0
@.str.4 = [38 x i8] c"Both files contain the same content!\0A\00"
@.str.5 = [58 x i8] c"The files are not the same!. Total differences found: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %1
store i32 1, i32* %2
store i32 0, i32* %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %57
12: ; preds = %0
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %57
17: ; preds = %12
br label %18
18: ; preds = %43, %17
%19 = load i32*, i32** %6
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %4
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32*, i32** %7
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %5
%28 = sext i8 %27 to i32
%29 = load i8, i8* @EOF
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %28, %30
br label %32
32: ; preds = %25, %18
%33 = phi i1 [ false, %18 ], [ %31, %25 ]
br i1 %33, label %34, label %44
34: ; preds = %32
%35 = load i8, i8* %4
%36 = call i64 @tolower(i8 signext %35)
%37 = load i8, i8* %5
%38 = call i64 @tolower(i8 signext %37)
%39 = icmp ne i64 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %34
store i32 0, i32* %2
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %43
43: ; preds = %40, %34
br label %18
44: ; preds = %32
%45 = load i32, i32* %2
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %52
49: ; preds = %44
%50 = load i32, i32* %3
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %47
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %1
br label %57
57: ; preds = %52, %15, %10
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [9 x i8] c"dat1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"I can't open it sorry!\00"
@.str.3 = [9 x i8] c"dat2.txt\00"
@EOF = global i8 0
@.str.5 = [58 x i8] c"The files are not the same!. Total differences found: %d\0A\00"
@str = [37 x i8] c"Both files contain the same content!\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %43
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call signext i8 @fgetc(i32* %1)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %36, label %14
12: ; preds = %5
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %43
14: ; preds = %8, %21
%15 = phi i8 [ %29, %21 ], [ %9, %8 ]
%16 = phi i32 [ %28, %21 ], [ 1, %8 ]
%17 = phi i32 [ %27, %21 ], [ 0, %8 ]
%18 = tail call signext i8 @fgetc(i32* %6)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %32, label %21
21: ; preds = %14
%22 = tail call i64 @tolower(i8 signext %15)
%23 = tail call i64 @tolower(i8 signext %18)
%24 = icmp eq i64 %22, %23
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %17, %26
%28 = select i1 %24, i32 %16, i32 0
%29 = tail call signext i8 @fgetc(i32* %1)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %32, label %14
32: ; preds = %14, %21
%33 = phi i32 [ %17, %14 ], [ %27, %21 ]
%34 = phi i32 [ %16, %14 ], [ %28, %21 ]
%35 = icmp eq i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %8, %32
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %40
38: ; preds = %32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %33)
br label %40
40: ; preds = %38, %36
%41 = tail call i32 @fclose(i32* %1)
%42 = tail call i32 @fclose(i32* %6)
br label %43
43: ; preds = %40, %12, %3
%44 = phi i32 [ -1, %3 ], [ -1, %12 ], [ 0, %40 ]
ret i32 %44
}