#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int);
int /*<<< orphan*/ int_print(int, int *);
int /*<<< orphan*/ merge(int, int *, int, int *, int, int *);
int /*<<< orphan*/ stderr;
int merge_sort(int len, int *num) {
  fprintf(
      stderr,
      "DEBUG %s:%d: "
      "merge_sort: len = %d"
      "\n",
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/search.h",
      80, len);
  int_print(len, num);
  if (len == 1) {
    return 0;
  }
  int mid = len / 2;
  merge_sort(mid, num);
  merge_sort(len - mid, &num[mid]);
  merge(mid, num, len - mid, &num[mid], len, num);
  return 0;
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%r8d
lea    0xe9d(%rip),%rsi
lea    0xeb9(%rip),%rdx
mov    $0x50,%ecx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <int_print@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1196 <merge_sort+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11fa <merge_sort+0xba>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <merge_sort@plt>
mov    -0x8(%rbp),%edi
sub    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1060 <merge_sort@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
sub    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x8(%rbp),%r8d
mov    -0x10(%rbp),%r9
call   1050 <merge@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
lea    0xebf(%rip),%rdx
mov    $0x50,%ecx
mov    %ebx,%r8d
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <int_print@plt>
cmp    $0x1,%ebx
je     11c1 <merge_sort+0x81>
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <merge_sort@plt>
mov    %ebx,%r15d
sub    %ebp,%r15d
movslq %ebp,%rbp
lea    (%r14,%rbp,4),%r12
mov    %r15d,%edi
mov    %r12,%rsi
call   1060 <merge_sort@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
mov    %ebx,%r8d
mov    %r14,%r9
call   1050 <merge@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"DEBUG %s:%d: merge_sort: len = %d\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/search.h\00"
define i32 @merge_sort(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* @stderr
%8 = load i32, i32* %4
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 80, i32 %8)
%10 = load i32, i32* %4
%11 = load i32*, i32** %5
%12 = call i32 @int_print(i32 %10, i32* %11)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %42
16: ; preds = %2
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 2
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32*, i32** %5
%21 = call i32 @merge_sort(i32 %19, i32* %20)
%22 = load i32, i32* %4
%23 = load i32, i32* %6
%24 = sub nsw i32 %22, %23
%25 = load i32*, i32** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 @merge_sort(i32 %24, i32* %28)
%30 = load i32, i32* %6
%31 = load i32*, i32** %5
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = sub nsw i32 %32, %33
%35 = load i32*, i32** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %4
%40 = load i32*, i32** %5
%41 = call i32 @merge(i32 %30, i32* %31, i32 %34, i32* %38, i32 %39, i32* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %16, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"DEBUG %s:%d: merge_sort: len = %d\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Faur/C_basics/refs/heads/master/src/search.h\00"
define i32 @merge_sort(i32 %0, i32* %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 80, i32 %0)
%5 = tail call i32 @int_print(i32 %0, i32* %1)
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %8
7: ; preds = %2, %8
ret i32 0
8: ; preds = %2
%9 = sdiv i32 %0, 2
%10 = tail call i32 @merge_sort(i32 %9, i32* %1)
%11 = sub nsw i32 %0, %9
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = tail call i32 @merge_sort(i32 %11, i32* %13)
%15 = tail call i32 @merge(i32 %9, i32* %1, i32 %11, i32* %13, i32 %0, i32* %1)
br label %7
}