#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 clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int atoi(char *);
scalar_t__ calculate_trapez(int);
int clock();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage trapez <N>\n");
    return 0;
  }
  int N = atoi(argv[1]);
  clock_t start = clock() / (CLOCKS_PER_SEC / 1000);
  double total_result = 0;
  total_result += calculate_trapez(N);
  clock_t end = (clock() / (CLOCKS_PER_SEC / 1000) - start);
  printf("%f\n%ld ms\n", total_result, end);
}


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   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <calculate_trapez@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
sub    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11e3 <main+0x93>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <clock@plt>
mov    0x2e6e(%rip),%r14
movslq (%r14),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <calculate_trapez@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <clock@plt>
movslq (%r14),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
sub    %ebp,%eax
lea    0xe2e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    11ef <main+0x9f>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage trapez <N>\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [11 x i8] c"%f\0A%ld ms\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
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, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %37
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = call i32 (...) @clock()
%20 = load i32, i32* @CLOCKS_PER_SEC
%21 = sdiv i32 %20, 1000
%22 = sdiv i32 %19, %21
store i32 %22, i32* %7
store double 0.000000e+00, double* %8
%23 = load i32, i32* %6
%24 = call i64 @calculate_trapez(i32 %23)
%25 = sitofp i64 %24 to double
%26 = load double, double* %8
%27 = fadd double %26, %25
store double %27, double* %8
%28 = call i32 (...) @clock()
%29 = load i32, i32* @CLOCKS_PER_SEC
%30 = sdiv i32 %29, 1000
%31 = sdiv i32 %28, %30
%32 = load i32, i32* %7
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %9
%34 = load double, double* %8
%35 = load i32, i32* %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %34, i32 %35)
br label %37
37: ; preds = %14, %12
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [11 x i8] c"%f\0A%ld ms\0A\00"
@str = [17 x i8] c"Usage trapez <N>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 (...) @clock()
%11 = load i32, i32* @CLOCKS_PER_SEC
%12 = sdiv i32 %11, 1000
%13 = sdiv i32 %10, %12
%14 = tail call i64 @calculate_trapez(i32 %9)
%15 = sitofp i64 %14 to double
%16 = tail call i32 (...) @clock()
%17 = load i32, i32* @CLOCKS_PER_SEC
%18 = sdiv i32 %17, 1000
%19 = sdiv i32 %16, %18
%20 = sub nsw i32 %19, %13
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %15, i32 %20)
br label %22
22: ; preds = %6, %4
ret i32 0
}