#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 */
scalar_t__ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
void *malloc(int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int process(void *x, int elementsize, int (*elementorder)(void *, void *),
            FILE *inputfile, FILE *outputfile) {
  int endofrun;
  void *y = malloc(elementsize);
  fwrite(x, elementsize, 1, outputfile);
  memcpy(y, x, elementsize);
  if (fread(x, elementsize, 1, inputfile) == 0)
    endofrun = 1;
  else
    endofrun = !elementorder(y, x);
  free(y);
  return endofrun;
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jne    11c7 <process+0x77>
movl   $0x1,-0x2c(%rbp)
jmp    11e5 <process+0x95>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%r13
mov    %rdx,(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1070 <fwrite@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11c4 <process+0x74>
mov    %r15,%rdi
mov    %rbx,%rsi
call   *(%rsp)
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @process(i8* %0, i32 %1, i32 (i8*, i8*)* %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 (i8*, i8*)* %2, i32 (i8*, i8*)** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i32, i32* %7
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %12
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = load i32*, i32** %10
%18 = call i32 @fwrite(i8* %15, i32 %16, i32 1, i32* %17)
%19 = load i8*, i8** %12
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @memcpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = load i32*, i32** %9
%26 = call i64 @fread(i8* %23, i32 %24, i32 1, i32* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %5
store i32 1, i32* %11
br label %37
29: ; preds = %5
%30 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%31 = load i8*, i8** %12
%32 = load i8*, i8** %6
%33 = call i32 %30(i8* %31, i8* %32)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
store i32 %36, i32* %11
br label %37
37: ; preds = %29, %28
%38 = load i8*, i8** %12
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* %11
ret i32 %40
}

LLVM IR (-O2):
define i32 @process(i8* %0, i32 %1, i32 (i8*, i8*)* nocapture %2, i32* nocapture %3, i32* nocapture %4) {
%6 = tail call i8* @malloc(i32 %1)
%7 = tail call i32 @fwrite(i8* %0, i32 %1, i32 1, i32* %4)
%8 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %1)
%9 = tail call i64 @fread(i8* %0, i32 %1, i32 1, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = tail call i32 %2(i8* %6, i8* %0)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %5, %11
%16 = phi i32 [ %14, %11 ], [ 1, %5 ]
%17 = tail call i32 @free(i8* %6)
ret i32 %16
}