#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ timevalsub(struct timeval *, struct timeval, struct timeval);
void timediff(void) {
  struct timeval t, nt, dt;
  int i;
  for (i = 0; i < 10; i++) {
    gettimeofday(&t, NULL);
    sleep(1);
    gettimeofday(&nt, NULL);
    timevalsub(&dt, nt, t);
    printf("%ld %ld\n", dt.tv_sec, dt.tv_usec);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11cc <timediff+0x7c>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1060 <timevalsub@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <timediff+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xa,%ebp
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
mov    %rsp,%r12
lea    0xe89(%rip),%r13
mov    0x2e62(%rip),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    %r12,%rdi
call   1060 <timevalsub@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
add    $0xffffffff,%ebp
jne    1180 <timediff+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [9 x i8] c"%ld %ld\0A\00"
@stdout = global i32 0
define void @timediff() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 0, i32* %4
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%10 = call i32 @sleep(i32 1)
%11 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%12 = bitcast %struct.timeval* %2 to i64*
%13 = load i64, i64* %12
%14 = bitcast %struct.timeval* %1 to i64*
%15 = load i64, i64* %14
%16 = call i32 @timevalsub(%struct.timeval* %3, i64 %13, i64 %15)
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
br label %24
24: ; preds = %8
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %5
27: ; preds = %5
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [9 x i8] c"%ld %ld\0A\00"
@stdout = global i32 0
define void @timediff() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timeval*
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timeval*
%5 = alloca %struct.timeval
%6 = bitcast i64* %1 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
br label %11
11: ; preds = %0, %11
%12 = phi i32 [ 0, %0 ], [ %24, %11 ]
%13 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%14 = call i32 @sleep(i32 1)
%15 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%16 = load i64, i64* %3
%17 = load i64, i64* %1
%18 = call i32 @timevalsub(%struct.timeval* %5, i64 %16, i64 %17)
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = add nuw nsw i32 %12, 1
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %11
26: ; preds = %11
ret void
}