#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 /*<<< orphan*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rmlb(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int diff(char *name1, char *name2) {
  FILE *f1, *f2;
  if ((f1 = fopen(name1, "r")) == NULL || (f2 = fopen(name2, "r")) == NULL) {
    fprintf(stderr, "Error: cannot open file: %s\n",
            f1 == NULL ? name1 : name2);
    exit(1);
  }
  char s1[1000], s2[1000], *p1, *p2;
  int line = 0;
  while (++line, p1 = fgets(s1, 1000, f1), p2 = fgets(s2, 1000, f2),
         p1 != NULL && p2 != NULL) {
    rmlb(s1);
    rmlb(s2);
    if (strcmp(s1, s2) != 0) {
      printf("First different at line:%d\n", line);
      printf("%s: %s\n%s: %s\n", name1, s1, name2, s2);
      return line;
    }
  }
  if (p1 != NULL || p2 != NULL) {
    printf("File: %s reached EOF or encounters an error.\n",
           f1 == NULL ? name1 : name2);
    return line;
  }
  printf("No diff.");
  return 0;
}


x86 assembly (clang, -O0):
<diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11bf <diff+0x4f>
mov    -0x18(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1217 <diff+0xa7>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x818(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <diff+0x79>
mov    -0x10(%rbp),%rax
mov    %rax,-0x820(%rbp)
jmp    11f4 <diff+0x84>
mov    -0x18(%rbp),%rax
mov    %rax,-0x820(%rbp)
mov    -0x818(%rbp),%edi
mov    -0x820(%rbp),%rdx
lea    0xdfa(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x814(%rbp)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
mov    %rax,-0x808(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
mov    %rax,-0x810(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x808(%rbp)
mov    %al,-0x821(%rbp)
je     128f <diff+0x11f>
cmpq   $0x0,-0x810(%rbp)
setne  %al
mov    %al,-0x821(%rbp)
mov    -0x821(%rbp),%al
test   $0x1,%al
jne    12a2 <diff+0x132>
jmp    1322 <diff+0x1b2>
lea    -0x410(%rbp),%rdi
call   1090 <rmlb@plt>
lea    -0x800(%rbp),%rdi
call   1090 <rmlb@plt>
lea    -0x410(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     131d <diff+0x1ad>
mov    -0x814(%rbp),%esi
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    -0x410(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x800(%rbp),%r8
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139c <diff+0x22c>
jmp    1221 <diff+0xb1>
cmpq   $0x0,-0x808(%rbp)
jne    133e <diff+0x1ce>
cmpq   $0x0,-0x810(%rbp)
je     1387 <diff+0x217>
cmpq   $0x0,-0x20(%rbp)
jne    1359 <diff+0x1e9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x830(%rbp)
jmp    1364 <diff+0x1f4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    139c <diff+0x22c>
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e8,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12a6 <diff+0x136>
mov    %rax,%r12
mov    %rbp,0x8(%rsp)
lea    0xe55(%rip),%rsi
mov    %rbx,(%rsp)
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12ab <diff+0x13b>
mov    %rax,%r13
mov    $0x1,%esi
lea    0x400(%rsp),%rbp
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %esi,%ebx
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %r15,%r15
je     1269 <diff+0xf9>
test   %rax,%rax
je     1269 <diff+0xf9>
mov    %rbp,%rdi
call   1090 <rmlb@plt>
mov    %r14,%rdi
call   1090 <rmlb@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
lea    0x1(%rbx),%esi
test   %rax,%rax
je     11e0 <diff+0x70>
add    $0xffffffff,%esi
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf1(%rip),%rdi
lea    0x400(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    0x8(%rsp),%rsi
mov    (%rsp),%rcx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1292 <diff+0x122>
or     %rax,%r15
je     1282 <diff+0x112>
lea    0xdd5(%rip),%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1292 <diff+0x122>
lea    0xdef(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdx
jmp    12af <diff+0x13f>
mov    (%rsp),%rdx
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error: cannot open file: %s\0A\00"
@.str.2 = [28 x i8] c"First different at line:%d\0A\00"
@.str.3 = [15 x i8] c"%s: %s\0A%s: %s\0A\00"
@.str.4 = [46 x i8] c"File: %s reached EOF or encounters an error.\0A\00"
@.str.5 = [9 x i8] c"No diff.\00"
define i32 @diff(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %32
20: ; preds = %16, %2
%21 = load i32, i32* @stderr
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i8*, i8** %4
br label %28
26: ; preds = %20
%27 = load i8*, i8** %5
br label %28
28: ; preds = %26, %24
%29 = phi i8* [ %25, %24 ], [ %27, %26 ]
%30 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %16
store i32 0, i32* %12
br label %33
33: ; preds = %67, %32
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i8* @fgets(i8* %36, i32 1000, i32* %37)
store i8* %38, i8** %10
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%40 = load i32*, i32** %7
%41 = call i8* @fgets(i8* %39, i32 1000, i32* %40)
store i8* %41, i8** %11
%42 = load i8*, i8** %10
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %33
%45 = load i8*, i8** %11
%46 = icmp ne i8* %45, null
br label %47
47: ; preds = %44, %33
%48 = phi i1 [ false, %33 ], [ %46, %44 ]
br i1 %48, label %49, label %68
49: ; preds = %47
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%51 = call i32 @rmlb(i8* %50)
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%53 = call i32 @rmlb(i8* %52)
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%56 = call i64 @strcmp(i8* %54, i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %67
58: ; preds = %49
%59 = load i32, i32* %12
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i8*, i8** %4
%62 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%63 = load i8*, i8** %5
%64 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %62, i8* %63, i8* %64)
%66 = load i32, i32* %12
store i32 %66, i32* %3
br label %87
67: ; preds = %49
br label %33
68: ; preds = %47
%69 = load i8*, i8** %10
%70 = icmp ne i8* %69, null
br i1 %70, label %74, label %71
71: ; preds = %68
%72 = load i8*, i8** %11
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %85
74: ; preds = %71, %68
%75 = load i32*, i32** %6
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = load i8*, i8** %4
br label %81
79: ; preds = %74
%80 = load i8*, i8** %5
br label %81
81: ; preds = %79, %77
%82 = phi i8* [ %78, %77 ], [ %80, %79 ]
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %82)
%84 = load i32, i32* %12
store i32 %84, i32* %3
br label %87
85: ; preds = %71
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %87
87: ; preds = %85, %81, %58
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error: cannot open file: %s\0A\00"
@.str.2 = [28 x i8] c"First different at line:%d\0A\00"
@.str.3 = [15 x i8] c"%s: %s\0A%s: %s\0A\00"
@.str.4 = [46 x i8] c"File: %s reached EOF or encounters an error.\0A\00"
@.str.5 = [9 x i8] c"No diff.\00"
define i32 @diff(i8* %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7, %2
%11 = phi i8* [ %1, %7 ], [ %0, %2 ]
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
br label %18
18: ; preds = %26, %15
%19 = phi i32 [ 0, %15 ], [ %20, %26 ]
%20 = add nuw nsw i32 %19, 1
%21 = call i8* @fgets(i8* %16, i32 1000, i32* %5)
%22 = call i8* @fgets(i8* %17, i32 1000, i32* %8)
%23 = icmp ne i8* %21, null
%24 = icmp ne i8* %22, null
%25 = and i1 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = call i32 @rmlb(i8* %16)
%28 = call i32 @rmlb(i8* %17)
%29 = call i64 @strcmp(i8* %16, i8* %17)
%30 = icmp eq i64 %29, 0
br i1 %30, label %18, label %31
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %16, i8* %1, i8* %17)
br label %40
34: ; preds = %18
%35 = or i1 %23, %24
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %1)
br label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %38, %36, %31
%41 = phi i32 [ %20, %31 ], [ %20, %36 ], [ 0, %38 ]
ret i32 %41
}