#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 tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, scalar_t__);
void set_time_end(struct timeval *tv) {
  struct timeval tv_now;
  struct timeval iv;
  gettimeofday(&tv_now, NULL);
  iv.tv_sec = tv_now.tv_sec - tv->tv_sec;
  if (tv->tv_usec > tv_now.tv_usec) {
    iv.tv_sec--;
    iv.tv_usec = tv->tv_usec + 1000000 - tv_now.tv_usec;
  } else
    iv.tv_usec = tv_now.tv_usec - tv->tv_usec;
  printf("time %u sec, %u usec\n", iv.tv_sec, iv.tv_usec);
}


x86 assembly (clang, -O0):
<set_time_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x10(%rbp),%rax
jle    117b <set_time_end+0x5b>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
add    $0xf4240,%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    118b <set_time_end+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_time_end>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%rdx
mov    0x8(%rbx),%rax
mov    %rdx,%rcx
sub    %rax,%rcx
mov    $0xf4240,%edi
sub    %rcx,%rdi
xor    %ecx,%ecx
sub    %rax,%rdx
mov    (%rsp),%esi
setl   %cl
cmovl  %rdi,%rdx
sub    (%rbx),%esi
sub    %ecx,%esi
lea    0xe9d(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [22 x i8] c"time %u sec, %u usec\0A\00"
define void @set_time_end(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %7, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 %11, i32* %12
%13 = load %struct.timeval*, %struct.timeval** %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp sgt i64 %15, %17
br i1 %18, label %19, label %31
19: ; preds = %1
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, -1
store i32 %22, i32* %20
%23 = load %struct.timeval*, %struct.timeval** %2
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = add nsw i64 %25, 1000000
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%28 = load i64, i64* %27
%29 = sub nsw i64 %26, %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 %29, i64* %30
br label %39
31: ; preds = %1
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%33 = load i64, i64* %32
%34 = load %struct.timeval*, %struct.timeval** %2
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = sub nsw i64 %33, %36
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 %37, i64* %38
br label %39
39: ; preds = %31, %19
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%43 = load i64, i64* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %41, i64 %43)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [22 x i8] c"time %u sec, %u usec\0A\00"
define void @set_time_end(%struct.timeval* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = sub i32 %6, %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = icmp slt i64 %13, %11
%15 = add nsw i64 %11, 1000000
%16 = sub i64 %15, %13
%17 = sub nsw i64 %13, %11
%18 = select i1 %14, i64 %16, i64 %17
%19 = sext i1 %14 to i32
%20 = add nsw i32 %9, %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20, i64 %18)
ret void
}