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

/* Variables and functions */
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ bailout(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ memcmp(char *, char *, size_t);
int /*<<< orphan*/ printf(char *);
char *slurpfile(char *, size_t *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int system(char *);
int rundiff(const char *testname) {
  char filename[1024];
  char cmdline[1024];
  int outputno;
  char *result;
  size_t result_len;
  snprintf(filename, sizeof(filename), "results/%s.out", testname);
  result = slurpfile(filename, &result_len);
  outputno = 0;
  for (;;) {
    char *expected;
    size_t expected_len;
    if (outputno == 0)
      snprintf(filename, sizeof(filename), "expected/%s.out", testname);
    else
      snprintf(filename, sizeof(filename), "expected/%s_%d.out", testname,
               outputno);
    expected = slurpfile(filename, &expected_len);
    if (expected == NULL) {
      if (outputno == 0)
        bailout("could not open file %s: %s\n", filename, strerror(ENOENT));
      free(result);
      break;
    }
    if (expected_len == result_len &&
        memcmp(expected, result, expected_len) == 0) {
      free(result);
      free(expected);
      return 0;
    }
    free(expected);
    outputno++;
  }
  snprintf(cmdline, sizeof(cmdline),
           "diff -c expected/%s.out results/%s.out >> regression.diffs",
           testname, testname);
  if (system(cmdline) == -1)
    printf("# diff failed\n");
  return 1;
}


x86 assembly (clang, -O0):
<rundiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe5a(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x828(%rbp),%rsi
call   1090 <slurpfile@plt>
mov    %rax,-0x820(%rbp)
movl   $0x0,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jne    1201 <rundiff+0x81>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe1a(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    1226 <rundiff+0xa6>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x814(%rbp),%r8d
mov    $0x400,%esi
lea    0xe00(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x838(%rbp),%rsi
call   1090 <slurpfile@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
jne    129d <rundiff+0x11d>
cmpl   $0x0,-0x814(%rbp)
jne    128c <rundiff+0x10c>
lea    -0x410(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x840(%rbp),%rsi
mov    %eax,%edx
lea    0xdab(%rip),%rdi
call   1040 <bailout@plt>
mov    -0x820(%rbp),%rdi
call   1030 <free@plt>
jmp    1319 <rundiff+0x199>
mov    -0x838(%rbp),%rax
cmp    -0x828(%rbp),%rax
jne    12f9 <rundiff+0x179>
mov    -0x830(%rbp),%rdi
mov    -0x820(%rbp),%rsi
mov    -0x838(%rbp),%rdx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    12f9 <rundiff+0x179>
mov    -0x820(%rbp),%rdi
call   1030 <free@plt>
mov    -0x830(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1363 <rundiff+0x1e3>
mov    -0x830(%rbp),%rdi
call   1030 <free@plt>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    11d1 <rundiff+0x51>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x400,%esi
lea    0xd1a(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x810(%rbp),%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
jne    135c <rundiff+0x1dc>
lea    0xd32(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rundiff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r15
lea    0xe65(%rip),%rdx
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <slurpfile@plt>
mov    %rax,%r14
lea    0x10(%rsp),%r13
xor    %r12d,%r12d
jmp    11dc <rundiff+0x5c>
nop
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%r12d
mov    %rbx,%rdi
mov    $0x400,%esi
test   %r12d,%r12d
je     1220 <rundiff+0xa0>
lea    0xe2f(%rip),%rdx
mov    %r15,%rcx
mov    %r12d,%r8d
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <slurpfile@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1244 <rundiff+0xc4>
jmp    129c <rundiff+0x11c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xde8(%rip),%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <slurpfile@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1278 <rundiff+0xf8>
mov    0x10(%rsp),%rdx
cmp    0x8(%rsp),%rdx
jne    11d0 <rundiff+0x50>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <memcmp@plt>
test   %rax,%rax
jne    11d0 <rundiff+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    12e3 <rundiff+0x163>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xda5(%rip),%rdi
lea    0x410(%rsp),%rsi
mov    %eax,%edx
call   1050 <bailout@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xda3(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
jne    12e3 <rundiff+0x163>
lea    0xdab(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"results/%s.out\00"
@.str.1 = [16 x i8] c"expected/%s.out\00"
@.str.2 = [19 x i8] c"expected/%s_%d.out\00"
@.str.3 = [28 x i8] c"could not open file %s: %s\0A\00"
@ENOENT = global i32 0
@.str.4 = [59 x i8] c"diff -c expected/%s.out results/%s.out >> regression.diffs\00"
@.str.5 = [15 x i8] c"# diff failed\0A\00"
define i32 @rundiff(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %11, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i8* @slurpfile(i8* %14, i64* %8)
store i8* %15, i8** %7
store i32 0, i32* %6
br label %16
16: ; preds = %59, %1
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %28
23: ; preds = %16
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %24, i32 1024, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %26)
br label %28
28: ; preds = %23, %19
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = call i8* @slurpfile(i8* %29, i64* %10)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%38 = load i32, i32* @ENOENT
%39 = call i32 @strerror(i32 %38)
%40 = call i32 @bailout(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %37, i32 %39)
br label %41
41: ; preds = %36, %33
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
br label %64
44: ; preds = %28
%45 = load i64, i64* %10
%46 = load i64, i64* %8
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i8*, i8** %9
%50 = load i8*, i8** %7
%51 = load i64, i64* %10
%52 = call i64 @memcmp(i8* %49, i8* %50, i64 %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %48
%55 = load i8*, i8** %7
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %9
%58 = call i32 @free(i8* %57)
store i32 0, i32* %2
br label %75
59: ; preds = %48, %44
%60 = load i8*, i8** %9
%61 = call i32 @free(i8* %60)
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %16
64: ; preds = %41
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%66 = load i8*, i8** %3
%67 = load i8*, i8** %3
%68 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %65, i32 1024, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %67)
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%70 = call i32 @system(i8* %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %64
%73 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %64
store i32 1, i32* %2
br label %75
75: ; preds = %74, %54
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@.str = [15 x i8] c"results/%s.out\00"
@.str.1 = [16 x i8] c"expected/%s.out\00"
@.str.2 = [19 x i8] c"expected/%s_%d.out\00"
@.str.3 = [28 x i8] c"could not open file %s: %s\0A\00"
@ENOENT = global i32 0
@.str.4 = [59 x i8] c"diff -c expected/%s.out results/%s.out >> regression.diffs\00"
@str = [14 x i8] c"# diff failed\00"
define i32 @rundiff(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast i64* %4 to i8*
%9 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i8* @slurpfile(i8* %6, i64* %4)
%11 = bitcast i64* %5 to i8*
br label %12
12: ; preds = %38, %1
%13 = phi i32 [ 0, %1 ], [ %40, %38 ]
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = call i8* @slurpfile(i8* %6, i64* %5)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %27
19: ; preds = %12
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %13)
%21 = call i8* @slurpfile(i8* %6, i64* %5)
%22 = icmp eq i8* %21, null
br i1 %22, label %41, label %27
23: ; preds = %15
%24 = load i32, i32* @ENOENT
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @bailout(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %25)
br label %41
27: ; preds = %19, %15
%28 = phi i8* [ %21, %19 ], [ %17, %15 ]
%29 = load i64, i64* %5
%30 = load i64, i64* %4
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = call i64 @memcmp(i8* %28, i8* %10, i64 %29)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @free(i8* %10)
%37 = call i32 @free(i8* %28)
br label %48
38: ; preds = %27, %32
%39 = call i32 @free(i8* %28)
%40 = add nuw nsw i32 %13, 1
br label %12
41: ; preds = %19, %23
%42 = call i32 @free(i8* %10)
%43 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %0)
%44 = call i32 @system(i8* %7)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %35, %41, %46
%49 = phi i32 [ 1, %46 ], [ 1, %41 ], [ 0, %35 ]
ret i32 %49
}