#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 */
int EOF;
int /*<<< orphan*/ free(char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *toBin(int, char **, int const);
void dump_and_compare(FILE *one, FILE *two, const int bitsPerComponent) {
  printf("Comparing two files:\n");
  int char1 = getc(one);
  int char2 = getc(two);
  char *c1 = NULL;
  char *c2 = NULL;
  while (char1 != EOF && char2 != EOF) {
    c1 = toBin(char1, &c1, bitsPerComponent);
    c2 = toBin(char2, &c2, bitsPerComponent);
    printf("--------------------\n %c = %s\n %c = %s\n", char1, c1, char2, c2);
    char1 = getc(one);
    char2 = getc(two);
  }
  free(c1);
  free(c2);
}


x86 assembly (clang, -O0):
<dump_and_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
mov    0x2e53(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     11b2 <dump_and_compare+0x72>
mov    -0x1c(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c2 <dump_and_compare+0x82>
jmp    1221 <dump_and_compare+0xe1>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1060 <toBin@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x30(%rbp),%rsi
call   1060 <toBin@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%r8
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x1c(%rbp)
jmp    1189 <dump_and_compare+0x49>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_and_compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,%ebx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
xor    %edi,%edi
cmp    %eax,%ebp
je     1228 <dump_and_compare+0xd8>
cmp    %eax,%ebx
je     1228 <dump_and_compare+0xd8>
lea    0xe49(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
lea    0x8(%rsp),%rsi
mov    %r12d,%edx
call   1070 <toBin@plt>
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1070 <toBin@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,%ebx
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebp
je     1223 <dump_and_compare+0xd3>
cmp    %eax,%ebx
jne    11c0 <dump_and_compare+0x70>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Comparing two files:\0A\00"
@EOF = global i32 0
@.str.1 = [40 x i8] c"--------------------\0A %c = %s\0A %c = %s\0A\00"
define void @dump_and_compare(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = load i32*, i32** %4
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %7
%14 = load i32*, i32** %5
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
br label %16
16: ; preds = %26, %3
%17 = load i32, i32* %7
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %8
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br label %24
24: ; preds = %20, %16
%25 = phi i1 [ false, %16 ], [ %23, %20 ]
br i1 %25, label %26, label %42
26: ; preds = %24
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = call i8* @toBin(i32 %27, i8** %9, i32 %28)
store i8* %29, i8** %9
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = call i8* @toBin(i32 %30, i8** %10, i32 %31)
store i8* %32, i8** %10
%33 = load i32, i32* %7
%34 = load i8*, i8** %9
%35 = load i32, i32* %8
%36 = load i8*, i8** %10
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %34, i32 %35, i8* %36)
%38 = load i32*, i32** %4
%39 = call i32 @getc(i32* %38)
store i32 %39, i32* %7
%40 = load i32*, i32** %5
%41 = call i32 @getc(i32* %40)
store i32 %41, i32* %8
br label %16
42: ; preds = %24
%43 = load i8*, i8** %9
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %10
%46 = call i32 @free(i8* %45)
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [40 x i8] c"--------------------\0A %c = %s\0A %c = %s\0A\00"
@str = [21 x i8] c"Comparing two files:\00"
define void @dump_and_compare(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @getc(i32* %0)
%8 = tail call i32 @getc(i32* %1)
%9 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%10 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %7, %11
%13 = icmp ne i32 %8, %11
%14 = and i1 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %3, %15
%16 = phi i32 [ %23, %15 ], [ %8, %3 ]
%17 = phi i32 [ %22, %15 ], [ %7, %3 ]
%18 = call i8* @toBin(i32 %17, i8** %4, i32 %2)
store i8* %18, i8** %4
%19 = call i8* @toBin(i32 %16, i8** %5, i32 %2)
store i8* %19, i8** %5
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %20, i32 %16, i8* %19)
%22 = call i32 @getc(i32* %0)
%23 = call i32 @getc(i32* %1)
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %22, %24
%26 = icmp ne i32 %23, %24
%27 = and i1 %25, %26
br i1 %27, label %15, label %28
28: ; preds = %15
%29 = load i8*, i8** %4
br label %30
30: ; preds = %28, %3
%31 = phi i8* [ %29, %28 ], [ null, %3 ]
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
ret void
}