#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ tvdelta(struct timeval *, struct timeval *);
long getoffset(void) {
  int i;
  struct timeval t, o;
  long delta = 0;
  for (i = 0; i < 100; i++) {
    gettimeofday(&o, NULL);
    gettimeofday(&t, NULL);
    delta += tvdelta(&t, &o);
  }
  return (delta / 100);
}


x86 assembly (clang, -O0):
<getoffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    117e <getoffset+0x5e>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <tvdelta@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1137 <getoffset+0x17>
mov    -0x18(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getoffset>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x64,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <tvdelta@plt>
add    %rax,%rbx
add    $0xffffffff,%ebp
jne    1140 <getoffset+0x20>
movabs $0xa3d70a3d70a3d70b,%rcx
0a d7 a3
mov    %rbx,%rax
imul   %rcx
add    %rdx,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x6,%rbx
add    %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define i64 @getoffset() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
store i64 0, i64* %4
store i32 0, i32* %1
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = call i64 @tvdelta(%struct.timeval* %2, %struct.timeval* %3)
%12 = load i64, i64* %4
%13 = add nsw i64 %12, %11
store i64 %13, i64* %4
br label %14
14: ; preds = %8
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %5
17: ; preds = %5
%18 = load i64, i64* %4
%19 = sdiv i64 %18, 100
ret i64 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define i64 @getoffset() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %11, %5 ]
%7 = phi i32 [ 0, %0 ], [ %12, %5 ]
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%10 = call i64 @tvdelta(%struct.timeval* %1, %struct.timeval* %2)
%11 = add nsw i64 %10, %6
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = sdiv i64 %11, 100
ret i64 %15
}