#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 EXIT_FAILURE;
int EXIT_SUCCESS;
size_t atoi(char *);
int /*<<< orphan*/ displayArray(size_t *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ generateArray(size_t *, size_t, size_t, size_t);
int /*<<< orphan*/ isSorted(size_t *, size_t);
size_t *malloc(int);
int /*<<< orphan*/ sort(size_t *, size_t);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  size_t *array;
  size_t min, max, size;
  if (argc != 4) {
    fprintf(stderr, "binary_sort array_size min_value max_value\n");
    return EXIT_FAILURE;
  }
  srand(time(NULL));
  size = atoi(argv[1]);
  min = atoi(argv[2]);
  max = atoi(argv[3]);
  array = malloc(sizeof(size_t) * size);
  if (!array) {
    fprintf(stderr, "Can note allocate memory for array\n");
    return EXIT_FAILURE;
  }
  if (min > max)
    generateArray(array, size, max, min);
  else
    generateArray(array, size, min, max);
  fprintf(stdout, "** Initial array **\n");
  displayArray(array, size);
  fprintf(stdout, "\n** Sorted array **\n");
  sort(array, size);
  displayArray(array, size);
  if (!isSorted(array, size)) {
    fprintf(stderr, "Array is not correctly sorted !\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11d6 <main+0x46>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1333 <main+0x1a3>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    125d <main+0xcd>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1333 <main+0x1a3>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    1285 <main+0xf5>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <generateArray@plt>
jmp    129a <main+0x10a>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <generateArray@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <displayArray@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <displayArray@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <isSorted@plt>
cmp    $0x0,%eax
jne    1327 <main+0x197>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1333 <main+0x1a3>
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    11fa <main+0x6a>
mov    %rsi,%rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rax,%r15
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rax,%r12
lea    0x0(,%r14,8),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1203 <main+0x73>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
cmp    %r12,%r15
jbe    120c <main+0x7c>
mov    %r12,%rdx
mov    %r15,%rcx
jmp    1212 <main+0x82>
lea    0xdff(%rip),%rsi
jmp    127c <main+0xec>
lea    0xe22(%rip),%rsi
jmp    127c <main+0xec>
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <generateArray@plt>
mov    0x2db2(%rip),%r15
mov    (%r15),%edi
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <displayArray@plt>
mov    (%r15),%edi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <sort@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <displayArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <isSorted@plt>
test   %eax,%eax
je     1275 <main+0xe5>
mov    0x2d55(%rip),%rax
jmp    1291 <main+0x101>
lea    0xdfe(%rip),%rsi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"binary_sort array_size min_value max_value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [36 x i8] c"Can note allocate memory for array\0A\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"** Initial array **\0A\00"
@.str.3 = [21 x i8] c"\0A** Sorted array **\0A\00"
@.str.4 = [33 x i8] c"Array is not correctly sorted !\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %81
16: ; preds = %2
%17 = call i32 @time(i32* null)
%18 = call i32 @srand(i32 %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @atoi(i8* %21)
store i64 %22, i64* %9
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @atoi(i8* %25)
store i64 %26, i64* %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i64 @atoi(i8* %29)
store i64 %30, i64* %8
%31 = load i64, i64* %9
%32 = mul i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i64* @malloc(i32 %33)
store i64* %34, i64** %6
%35 = load i64*, i64** %6
%36 = icmp ne i64* %35, null
br i1 %36, label %41, label %37
37: ; preds = %16
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %81
41: ; preds = %16
%42 = load i64, i64* %7
%43 = load i64, i64* %8
%44 = icmp ugt i64 %42, %43
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i64*, i64** %6
%47 = load i64, i64* %9
%48 = load i64, i64* %8
%49 = load i64, i64* %7
%50 = call i32 @generateArray(i64* %46, i64 %47, i64 %48, i64 %49)
br label %57
51: ; preds = %41
%52 = load i64*, i64** %6
%53 = load i64, i64* %9
%54 = load i64, i64* %7
%55 = load i64, i64* %8
%56 = call i32 @generateArray(i64* %52, i64 %53, i64 %54, i64 %55)
br label %57
57: ; preds = %51, %45
%58 = load i32, i32* @stdout
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%60 = load i64*, i64** %6
%61 = load i64, i64* %9
%62 = call i32 @displayArray(i64* %60, i64 %61)
%63 = load i32, i32* @stdout
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%65 = load i64*, i64** %6
%66 = load i64, i64* %9
%67 = call i32 @sort(i64* %65, i64 %66)
%68 = load i64*, i64** %6
%69 = load i64, i64* %9
%70 = call i32 @displayArray(i64* %68, i64 %69)
%71 = load i64*, i64** %6
%72 = load i64, i64* %9
%73 = call i32 @isSorted(i64* %71, i64 %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %79, label %75
75: ; preds = %57
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
store i32 %78, i32* %3
br label %81
79: ; preds = %57
%80 = load i32, i32* @EXIT_SUCCESS
store i32 %80, i32* %3
br label %81
81: ; preds = %79, %75, %37, %12
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"binary_sort array_size min_value max_value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [36 x i8] c"Can note allocate memory for array\0A\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"** Initial array **\0A\00"
@.str.3 = [21 x i8] c"\0A** Sorted array **\0A\00"
@.str.4 = [33 x i8] c"Array is not correctly sorted !\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i64 @atoi(i8* %14)
%16 = trunc i64 %9 to i32
%17 = shl i32 %16, 3
%18 = tail call i64* @malloc(i32 %17)
%19 = icmp eq i64* %18, null
br i1 %19, label %36, label %20
20: ; preds = %4
%21 = icmp ugt i64 %12, %15
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @generateArray(i64* %18, i64 %9, i64 %15, i64 %12)
br label %26
24: ; preds = %20
%25 = tail call i32 @generateArray(i64* %18, i64 %9, i64 %12, i64 %15)
br label %26
26: ; preds = %24, %22
%27 = load i32, i32* @stdout
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @displayArray(i64* %18, i64 %9)
%30 = load i32, i32* @stdout
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @sort(i64* %18, i64 %9)
%33 = tail call i32 @displayArray(i64* %18, i64 %9)
%34 = tail call i32 @isSorted(i64* %18, i64 %9)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %26, %4, %2
%37 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %26 ]
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* %37)
br label %40
40: ; preds = %36, %26
%41 = phi i32* [ @EXIT_SUCCESS, %26 ], [ @EXIT_FAILURE, %36 ]
%42 = load i32, i32* %41
ret i32 %42
}