#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 timeval {
  float tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *);
float profile_function(int *tb, int size, void (*func)(int *, int)) {
  int *copy = malloc(sizeof(*copy) * size);
  struct timeval tmp, tmp2;
  memcpy(copy, tb, size * sizeof(*tb));
  gettimeofday(&tmp, NULL);
  func(copy, size);
  gettimeofday(&tmp2, NULL);
  int i;
  for (i = 0; i < size - 1; i++) {
    if (copy[i] > copy[i + 1]) {
      printf("failure.\n");
      break;
    }
  }
  free(copy);
  return ((float)(tmp2.tv_sec - tmp.tv_sec)) +
         (tmp2.tv_usec - tmp.tv_usec) / 1000000.f;
}


x86 assembly (clang, -O0):
<profile_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   *%rax
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1211 <profile_function+0xc1>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x20(%rbp),%rcx
mov    -0x44(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11fe <profile_function+0xae>
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
jmp    1211 <profile_function+0xc1>
jmp    1203 <profile_function+0xb3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11bb <profile_function+0x6b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2ss %rax,%xmm0
movss  -0x40(%rbp),%xmm1
subss  -0x30(%rbp),%xmm1
movss  0xdc7(%rip),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<profile_function>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r12
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
xor    %ebp,%ebp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   *%r15
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
add    $0xffffffff,%r14d
test   %r14d,%r14d
cmovle %ebp,%r14d
cmp    %rbp,%r14
je     11d1 <profile_function+0x81>
mov    (%rbx,%rbp,4),%eax
lea    0x1(%rbp),%rcx
cmp    0x4(%rbx,%rbp,4),%eax
mov    %rcx,%rbp
jle    11b0 <profile_function+0x60>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
cvtsi2ss %rax,%xmm1
movss  (%rsp),%xmm0
subss  0x10(%rsp),%xmm0
divss  0xe05(%rip),%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { float, i64 }
@.str = [10 x i8] c"failure.\0A\00"
define float @profile_function(i32* %0, i32 %1, void (i32*, i32)* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca void (i32*, i32)*
%7 = alloca i32*
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store void (i32*, i32)* %2, void (i32*, i32)** %6
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i32 @memcpy(i32* %16, i32* %17, i32 %21)
%23 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%24 = load void (i32*, i32)*, void (i32*, i32)** %6
%25 = load i32*, i32** %7
%26 = load i32, i32* %5
%27 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
store i32 0, i32* %10
br label %28
28: ; preds = %49, %3
%29 = load i32, i32* %10
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 1
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %52
33: ; preds = %28
%34 = load i32*, i32** %7
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32*, i32** %7
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %38, %44
br i1 %45, label %46, label %48
46: ; preds = %33
%47 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %52
48: ; preds = %33
br label %49
49: ; preds = %48
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %28
52: ; preds = %46, %28
%53 = load i32*, i32** %7
%54 = call i32 @free(i32* %53)
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%56 = load i64, i64* %55
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%58 = load i64, i64* %57
%59 = sub nsw i64 %56, %58
%60 = sitofp i64 %59 to float
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%62 = load float, float* %61
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%64 = load float, float* %63
%65 = fsub float %62, %64
%66 = fdiv float %65, 1.000000e+06
%67 = fadd float %60, %66
ret float %67
}

LLVM IR (-O2):
%struct.timeval = type { float, i64 }
@str = [9 x i8] c"failure.\00"
define float @profile_function(i32* %0, i32 %1, void (i32*, i32)* nocapture %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = shl i32 %1, 2
%7 = tail call i32* @malloc(i32 %6)
%8 = bitcast %struct.timeval* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = tail call i32 @memcpy(i32* %7, i32* %0, i32 %6)
%11 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
tail call void %2(i32* %7, i32 %1)
%12 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%13 = add i32 %1, -1
%14 = call i32 @llvm.smax.i32(i32 %13, i32 0)
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %19, %3
%17 = phi i64 [ %22, %19 ], [ 0, %3 ]
%18 = icmp eq i64 %17, %15
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = getelementptr inbounds i32, i32* %7, i64 %17
%21 = load i32, i32* %20
%22 = add nuw nsw i64 %17, 1
%23 = getelementptr inbounds i32, i32* %7, i64 %22
%24 = load i32, i32* %23
%25 = icmp sgt i32 %21, %24
br i1 %25, label %26, label %16
26: ; preds = %19
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %16, %26
%29 = tail call i32 @free(i32* %7)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%33 = load i64, i64* %32
%34 = sub nsw i64 %31, %33
%35 = sitofp i64 %34 to float
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%37 = load float, float* %36
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%39 = load float, float* %38
%40 = fsub float %37, %39
%41 = fdiv float %40, 1.000000e+06
%42 = fadd float %41, %35
ret float %42
}