#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*/ SEEK_SET;
char *calloc(int, int);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ insert(int /*<<< orphan*/ *, int, int, char *,
                          int (*)(long const, char const *));
void sortFile(FILE *strings, int n, int s,
              int (*cmp)(const long, const char *)) {
  int i;
  char *saved = calloc(s, sizeof(char));
  for (i = 1; i < n; i++) {
    int fs = fseek(strings, i * s, SEEK_SET);
    int rt = fread(saved, s, 1, strings);
    insert(strings, i, s, saved, cmp);
  }
  free(saved);
}


x86 assembly (clang, -O0):
<sortFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e3 <sortFile+0x93>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
imul   -0x10(%rbp),%esi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1070 <insert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <sortFile+0x2e>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
mov    $0x1,%ebx
mov    %edx,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r13
cmp    $0x2,%r15d
jl     11d5 <sortFile+0x85>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
mov    %r13,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r13,%rcx
mov    (%rsp),%r8
call   1070 <insert@plt>
add    $0x1,%ebx
add    %r14d,%ebp
cmp    %ebx,%r15d
jne    1190 <sortFile+0x40>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
define void @sortFile(i32* %0, i32 %1, i32 %2, i32 (i64, i8*)* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32 (i64, i8*)*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 (i64, i8*)* %3, i32 (i64, i8*)** %8
%13 = load i32, i32* %7
%14 = call i8* @calloc(i32 %13, i32 1)
store i8* %14, i8** %10
store i32 1, i32* %9
br label %15
15: ; preds = %36, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %20, i32 %23, i32 %24)
store i32 %25, i32* %11
%26 = load i8*, i8** %10
%27 = load i32, i32* %7
%28 = load i32*, i32** %5
%29 = call i32 @fread(i8* %26, i32 %27, i32 1, i32* %28)
store i32 %29, i32* %12
%30 = load i32*, i32** %5
%31 = load i32, i32* %9
%32 = load i32, i32* %7
%33 = load i8*, i8** %10
%34 = load i32 (i64, i8*)*, i32 (i64, i8*)** %8
%35 = call i32 @insert(i32* %30, i32 %31, i32 %32, i8* %33, i32 (i64, i8*)* %34)
br label %36
36: ; preds = %19
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %15
39: ; preds = %15
%40 = load i8*, i8** %10
%41 = call i32 @free(i8* %40)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @sortFile(i32* %0, i32 %1, i32 %2, i32 (i64, i8*)* %3) {
%5 = tail call i8* @calloc(i32 %2, i32 1)
%6 = icmp sgt i32 %1, 1
br i1 %6, label %7, label %16
7: ; preds = %4, %7
%8 = phi i32 [ %14, %7 ], [ 1, %4 ]
%9 = mul nsw i32 %8, %2
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %0, i32 %9, i32 %10)
%12 = tail call i32 @fread(i8* %5, i32 %2, i32 1, i32* %0)
%13 = tail call i32 @insert(i32* %0, i32 %8, i32 %2, i8* %5, i32 (i64, i8*)* %3)
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %16, label %7
16: ; preds = %7, %4
%17 = tail call i32 @free(i8* %5)
ret void
}