#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 */
struct drm_intel_decode {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ drm_intel_decode(struct drm_intel_decode *);
int /*<<< orphan*/ drm_intel_decode_set_batch_pointer(struct drm_intel_decode *,
                                                      void *, int, size_t);
int /*<<< orphan*/ drm_intel_decode_set_output_file(struct drm_intel_decode *,
                                                    int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(void *);
char *malloc(scalar_t__);
int /*<<< orphan*/ read_file(char const *, void **, size_t *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(void *, void *);
scalar_t__ strlen(char const *);
void compare_batch(struct drm_intel_decode *ctx, const char *batch_filename) {
  FILE *out = NULL;
  void *ptr, *ref_ptr, *batch_ptr;
  size_t ref_size, batch_size;
  const char *ref_suffix = "-ref.txt";
  char *ref_filename;
  ref_filename = malloc(strlen(batch_filename) + strlen(ref_suffix) + 1);
  sprintf(ref_filename, "%s%s", batch_filename, ref_suffix);
  read_file(batch_filename, &batch_ptr, &batch_size);
  read_file(ref_filename, &ref_ptr, &ref_size);
  fprintf(stderr, "platform lacks open_memstream, skipping.\n");
  exit(77);
  drm_intel_decode_set_batch_pointer(ctx, batch_ptr, 0x12300000,
                                     batch_size / 4);
  drm_intel_decode_set_output_file(ctx, out);
  drm_intel_decode(ctx);
  if (strcmp(ref_ptr, ptr) != 0) {
    fprintf(stderr, "Decode mismatch with reference `%s'.\n", ref_filename);
    fprintf(stderr, "You can dump the new output using:\n");
    fprintf(stderr, "  test_decode \"%s\" -dump\n", batch_filename);
    exit(1);
  }
  fclose(out);
  free(ref_filename);
  free(ptr);
}


x86 assembly (clang, -O0):
<compare_batch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xe49(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <read_file@plt>
mov    -0x50(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <read_file@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x4d,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<compare_batch>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x9(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe84(%rip),%rsi
lea    0xe74(%rip),%rcx
mov    %rax,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <read_file@plt>
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1050 <read_file@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x4d,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.drm_intel_decode = type { i32 }
@.str = [9 x i8] c"-ref.txt\00"
@.str.1 = [5 x i8] c"%s%s\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"platform lacks open_memstream, skipping.\0A\00"
define void @compare_batch(%struct.drm_intel_decode* %0, i8* %1) {
%3 = alloca %struct.drm_intel_decode*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
store %struct.drm_intel_decode* %0, %struct.drm_intel_decode** %3
store i8* %1, i8** %4
store i32* null, i32** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %11
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %11
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %14, %16
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %12
%20 = load i8*, i8** %12
%21 = load i8*, i8** %4
%22 = load i8*, i8** %11
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @read_file(i8* %24, i8** %8, i64* %10)
%26 = load i8*, i8** %12
%27 = call i32 @read_file(i8* %26, i8** %7, i64* %9)
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 77)
unreachable
}

LLVM IR (-O2):
%struct.drm_intel_decode = type { i32 }
@.str = [9 x i8] c"-ref.txt\00"
@.str.1 = [5 x i8] c"%s%s\00"
@stderr = global i32 0
@.str.2 = [42 x i8] c"platform lacks open_memstream, skipping.\0A\00"
define void @compare_batch(%struct.drm_intel_decode* nocapture readnone %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%12 = add nsw i64 %11, 9
%13 = tail call i8* @malloc(i64 %12)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @read_file(i8* %1, i8** %4, i64* %6)
%16 = call i32 @read_file(i8* %13, i8** %3, i64* %5)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 77)
unreachable
}