#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 {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int BUFSIZ;
double atof(char *);
int /*<<< orphan*/ err_check(scalar_t__);
scalar_t__ errno;
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int t;
  double start, stop;
  char t_val[BUFSIZ];
  struct timeval c_time;
  errno = 0;
  if (argc == 1) {
    t = gettimeofday(&c_time, NULL);
    if (t < 0)
      printf("\nERROR\n");
    sprintf(t_val, "\n%ld.%03ld\n\n", c_time.tv_sec, c_time.tv_usec);
    start = atof(t_val);
    printf("\n%.3f\n\n", start);
  } else if (argc == 2) {
    t = gettimeofday(&c_time, NULL);
    if (t < 0)
      printf("\nERROR\n");
    sprintf(t_val, "%ld.%03ld\n", c_time.tv_sec, c_time.tv_usec);
    start = atof(argv[1]);
    stop = atof(t_val);
    printf("\nPrevious = %.3f  Current = %.3f\n\n", start, stop);
    printf("Time Interval = %.3f seconds\n\n", stop - start);
  } else
    printf("\nUsage: prgm_name <optional> prev_time\n\n");
  err_check(errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    0x2e3f(%rip),%rax
movq   $0x0,(%rax)
cmpl   $0x1,-0x8(%rbp)
jne    120e <main+0xbe>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d2 <main+0x82>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xe25(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe13(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12be <main+0x16e>
cmpl   $0x2,-0x8(%rbp)
jne    12ab <main+0x15b>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1240 <main+0xf0>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xdcc(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
mov    -0x48(%rbp),%rdi
movsd  %xmm0,-0x20(%rbp)
call   1040 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xda1(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
lea    0xdac(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12b9 <main+0x169>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12be <main+0x16e>
mov    0x2d13(%rip),%rax
mov    (%rax),%rdi
call   1030 <err_check@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e4a(%rip),%r15
movq   $0x0,(%r15)
cmp    $0x2,%edi
je     11e4 <main+0x84>
cmp    $0x1,%edi
jne    1262 <main+0x102>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
test   %eax,%eax
jns    11be <main+0x5e>
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%edx
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <atof@plt>
lea    0xe2b(%rip),%rdi
jmp    1259 <main+0xf9>
mov    %rsi,%r14
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
test   %eax,%eax
jns    1202 <main+0xa2>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    0x8(%r14),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    %rbx,%rdi
call   1050 <atof@plt>
movaps %xmm0,%xmm1
movsd  %xmm0,-0x30(%rbp)
lea    0xde4(%rip),%rdi
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%al
call   1060 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xdea(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    126e <main+0x10e>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
mov    (%r15),%rdi
call   1030 <err_check@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@BUFSIZ = global i32 0
@errno = global i64 0
@.str = [8 x i8] c"\0AERROR\0A\00"
@.str.1 = [13 x i8] c"\0A%ld.%03ld\0A\0A\00"
@.str.2 = [8 x i8] c"\0A%.3f\0A\0A\00"
@.str.3 = [11 x i8] c"%ld.%03ld\0A\00"
@.str.4 = [35 x i8] c"\0APrevious = %.3f Current = %.3f\0A\0A\00"
@.str.5 = [31 x i8] c"Time Interval = %.3f seconds\0A\0A\00"
@.str.6 = [41 x i8] c"\0AUsage: prgm_name <optional> prev_time\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
store i64 0, i64* @errno
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %33
18: ; preds = %2
%19 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28)
%30 = call double @atof(i8* %15)
store double %30, double* %7
%31 = load double, double* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %31)
br label %63
33: ; preds = %2
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 2
br i1 %35, label %36, label %60
36: ; preds = %33
%37 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %46)
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call double @atof(i8* %50)
store double %51, double* %7
%52 = call double @atof(i8* %15)
store double %52, double* %8
%53 = load double, double* %7
%54 = load double, double* %8
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %53, double %54)
%56 = load double, double* %8
%57 = load double, double* %7
%58 = fsub double %56, %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %58)
br label %62
60: ; preds = %33
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %60, %42
br label %63
63: ; preds = %62, %24
%64 = load i64, i64* @errno
%65 = call i32 @err_check(i64 %64)
store i32 0, i32* %3
%66 = load i8*, i8** %9
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@BUFSIZ = global i32 0
@errno = global i64 0
@.str.1 = [13 x i8] c"\0A%ld.%03ld\0A\0A\00"
@.str.2 = [8 x i8] c"\0A%.3f\0A\0A\00"
@.str.3 = [11 x i8] c"%ld.%03ld\0A\00"
@.str.4 = [35 x i8] c"\0APrevious = %.3f Current = %.3f\0A\0A\00"
@.str.5 = [31 x i8] c"Time Interval = %.3f seconds\0A\0A\00"
@str = [40 x i8] c"\0AUsage: prgm_name <optional> prev_time\0A\00"
@str.8 = [7 x i8] c"\0AERROR\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.timeval* %3 to i8*
store i64 0, i64* @errno
switch i32 %0, label %39 [
i32 1, label %8
i32 2, label %21
]
8: ; preds = %2
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %17)
%19 = call double @atof(i8* %6)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %19)
br label %41
21: ; preds = %2
%22 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %30)
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = tail call double @atof(i8* %33)
%35 = call double @atof(i8* %6)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), double %34, double %35)
%37 = fsub double %35, %34
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), double %37)
br label %41
39: ; preds = %2
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %26, %39, %13
%42 = load i64, i64* @errno
%43 = tail call i32 @err_check(i64 %42)
ret i32 0
}