#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*/ uint8_t;
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ _calc_gradients_by_mutiple_lines(int *, int /*<<< orphan*/ *,
                                                    int, int);
int /*<<< orphan*/ _calc_gradients_line_by_line(int *, int /*<<< orphan*/ *,
                                                int, int);
int /*<<< orphan*/ _calc_gradients_pix_by_pix(int *, int /*<<< orphan*/ *, int,
                                              int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
void calc_gradients_whole_pic(int *gradient, uint8_t *image, int width,
                              int height) {
  assert(gradient != NULL);
  assert(image != NULL);
  clock_t start;
  int repetitions = 50;
  printf("benchmarking ... repetitions %d\n", repetitions);
  start = clock();
  for (int i = 0; i < repetitions; i++) {
    ;
    _calc_gradients_pix_by_pix(gradient, image, width, height);
  }
  printf("\n[%s] elapsed time: %.4f\n", "OnePixelEachLoop",
         (double)(clock() - start) / CLOCKS_PER_SEC);
  ;
  start = clock();
  for (int i = 0; i < repetitions; i++) {
    ;
    _calc_gradients_line_by_line(gradient, image, width, height);
  }
  printf("\n[%s] elapsed time: %.4f\n", "OneLineEachLoop",
         (double)(clock() - start) / CLOCKS_PER_SEC);
  ;
  start = clock();
  for (int i = 0; i < repetitions; i++) {
    ;
    _calc_gradients_by_mutiple_lines(gradient, image, width, height);
  }
  printf("\n[%s] elapsed time: %.4f\n", "MultipleLinesEachLoop",
         (double)(clock() - start) / CLOCKS_PER_SEC);
  ;
}


x86 assembly (clang, -O0):
<calc_gradients_whole_pic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x32,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f1 <calc_gradients_whole_pic+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1080 <_calc_gradients_pix_by_pix@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c4 <calc_gradients_whole_pic+0x64>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2de0(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe0e(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1260 <calc_gradients_whole_pic+0x100>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <_calc_gradients_line_by_line@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1233 <calc_gradients_whole_pic+0xd3>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d71(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd9f(%rip),%rdi
lea    0xdc3(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12cf <calc_gradients_whole_pic+0x16f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <_calc_gradients_by_mutiple_lines@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12a2 <calc_gradients_whole_pic+0x142>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d02(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd30(%rip),%rdi
lea    0xd64(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_gradients_whole_pic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1070 <assert@plt>
lea    0xe66(%rip),%rdi
mov    $0x32,%ebx
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1080 <_calc_gradients_pix_by_pix@plt>
add    $0xffffffff,%ebx
jne    11c0 <calc_gradients_whole_pic+0x60>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12,%rax
cvtsi2sd %rax,%xmm0
mov    0x2dfc(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe2a(%rip),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    $0x32,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <_calc_gradients_line_by_line@plt>
add    $0xffffffff,%ebx
jne    1220 <calc_gradients_whole_pic+0xc0>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d99(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdc7(%rip),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    $0x32,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1060 <_calc_gradients_by_mutiple_lines@plt>
add    $0xffffffff,%ebx
jne    1280 <calc_gradients_whole_pic+0x120>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d39(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd67(%rip),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"benchmarking ... repetitions %d\0A\00"
@.str.1 = [26 x i8] c"\0A[%s] elapsed time: %.4f\0A\00"
@.str.2 = [17 x i8] c"OnePixelEachLoop\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [16 x i8] c"OneLineEachLoop\00"
@.str.4 = [22 x i8] c"MultipleLinesEachLoop\00"
define void @calc_gradients_whole_pic(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 50, i32* %10
%22 = load i32, i32* %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i64 (...) @clock()
store i64 %24, i64* %9
store i32 0, i32* %11
br label %25
25: ; preds = %35, %4
%26 = load i32, i32* %11
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32*, i32** %5
%31 = load i32*, i32** %6
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call i32 @_calc_gradients_pix_by_pix(i32* %30, i32* %31, i32 %32, i32 %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
br label %25
38: ; preds = %25
%39 = call i64 (...) @clock()
%40 = load i64, i64* %9
%41 = sub nsw i64 %39, %40
%42 = sitofp i64 %41 to double
%43 = load double, double* @CLOCKS_PER_SEC
%44 = fdiv double %42, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double %44)
%46 = call i64 (...) @clock()
store i64 %46, i64* %9
store i32 0, i32* %12
br label %47
47: ; preds = %57, %38
%48 = load i32, i32* %12
%49 = load i32, i32* %10
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load i32*, i32** %5
%53 = load i32*, i32** %6
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = call i32 @_calc_gradients_line_by_line(i32* %52, i32* %53, i32 %54, i32 %55)
br label %57
57: ; preds = %51
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
br label %47
60: ; preds = %47
%61 = call i64 (...) @clock()
%62 = load i64, i64* %9
%63 = sub nsw i64 %61, %62
%64 = sitofp i64 %63 to double
%65 = load double, double* @CLOCKS_PER_SEC
%66 = fdiv double %64, %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %66)
%68 = call i64 (...) @clock()
store i64 %68, i64* %9
store i32 0, i32* %13
br label %69
69: ; preds = %79, %60
%70 = load i32, i32* %13
%71 = load i32, i32* %10
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %82
73: ; preds = %69
%74 = load i32*, i32** %5
%75 = load i32*, i32** %6
%76 = load i32, i32* %7
%77 = load i32, i32* %8
%78 = call i32 @_calc_gradients_by_mutiple_lines(i32* %74, i32* %75, i32 %76, i32 %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %13
%81 = add nsw i32 %80, 1
store i32 %81, i32* %13
br label %69
82: ; preds = %69
%83 = call i64 (...) @clock()
%84 = load i64, i64* %9
%85 = sub nsw i64 %83, %84
%86 = sitofp i64 %85 to double
%87 = load double, double* @CLOCKS_PER_SEC
%88 = fdiv double %86, %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %88)
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"benchmarking ... repetitions %d\0A\00"
@.str.1 = [26 x i8] c"\0A[%s] elapsed time: %.4f\0A\00"
@.str.2 = [17 x i8] c"OnePixelEachLoop\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [16 x i8] c"OneLineEachLoop\00"
@.str.4 = [22 x i8] c"MultipleLinesEachLoop\00"
define void @calc_gradients_whole_pic(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp ne i32* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i32* %1, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 50)
%12 = tail call i64 (...) @clock()
br label %21
13: ; preds = %21
%14 = tail call i64 (...) @clock()
%15 = sub nsw i64 %14, %12
%16 = sitofp i64 %15 to double
%17 = load double, double* @CLOCKS_PER_SEC
%18 = fdiv double %16, %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = tail call i64 (...) @clock()
br label %34
21: ; preds = %4, %21
%22 = phi i32 [ 0, %4 ], [ %24, %21 ]
%23 = tail call i32 @_calc_gradients_pix_by_pix(i32* %0, i32* %1, i32 %2, i32 %3)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, 50
br i1 %25, label %13, label %21
26: ; preds = %34
%27 = tail call i64 (...) @clock()
%28 = sub nsw i64 %27, %20
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %31)
%33 = tail call i64 (...) @clock()
br label %46
34: ; preds = %13, %34
%35 = phi i32 [ 0, %13 ], [ %37, %34 ]
%36 = tail call i32 @_calc_gradients_line_by_line(i32* %0, i32* %1, i32 %2, i32 %3)
%37 = add nuw nsw i32 %35, 1
%38 = icmp eq i32 %37, 50
br i1 %38, label %26, label %34
39: ; preds = %46
%40 = tail call i64 (...) @clock()
%41 = sub nsw i64 %40, %33
%42 = sitofp i64 %41 to double
%43 = load double, double* @CLOCKS_PER_SEC
%44 = fdiv double %42, %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %44)
ret void
46: ; preds = %26, %46
%47 = phi i32 [ 0, %26 ], [ %49, %46 ]
%48 = tail call i32 @_calc_gradients_by_mutiple_lines(i32* %0, i32* %1, i32 %2, i32 %3)
%49 = add nuw nsw i32 %47, 1
%50 = icmp eq i32 %49, 50
br i1 %50, label %39, label %46
}