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

/* Variables and functions */
void tvsqr(struct timeval *tv) {
  tv->tv_sec *= tv->tv_sec;
  tv->tv_usec *= tv->tv_usec;
  while ((unsigned long)tv->tv_usec > 1000000) {
    tv->tv_sec++;
    tv->tv_usec -= 1000000;
  }
}


x86 assembly (clang, -O0):
<tvsqr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
imul   0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
imul   (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
cmp    $0xf4240,%rax
jbe    115c <tvsqr+0x5c>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
jmp    1129 <tvsqr+0x29>
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvsqr>:
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
imul   %ecx,%ecx
mov    %ecx,0x4(%rdi)
imul   %eax,%eax
cmp    $0xf4241,%eax
jb     113b <tvsqr+0x3b>
lea    -0xf4241(%rax),%edx
imul   $0x431bde83,%rdx,%rdx
shr    $0x32,%rdx
add    %edx,%ecx
add    $0x1,%ecx
imul   $0xfff0bdc0,%edx,%edx
add    %edx,%eax
add    $0xfff0bdc0,%eax
mov    %ecx,0x4(%rdi)
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @tvsqr(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %2
%3 = load %struct.timeval*, %struct.timeval** %2
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%5 = load i32, i32* %4
%6 = load %struct.timeval*, %struct.timeval** %2
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, %5
store i32 %9, i32* %7
%10 = load %struct.timeval*, %struct.timeval** %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.timeval*, %struct.timeval** %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, %12
store i32 %16, i32* %14
br label %17
17: ; preds = %23, %1
%18 = load %struct.timeval*, %struct.timeval** %2
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = icmp ugt i64 %21, 1000000
br i1 %22, label %23, label %32
23: ; preds = %17
%24 = load %struct.timeval*, %struct.timeval** %2
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
%28 = load %struct.timeval*, %struct.timeval** %2
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = sub nsw i32 %30, 1000000
store i32 %31, i32* %29
br label %17
32: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @tvsqr(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%3 = load i32, i32* %2
%4 = mul nsw i32 %3, %3
store i32 %4, i32* %2
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = mul i32 %6, %6
%8 = icmp ugt i32 %7, 1000000
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = add i32 %7, -1000001
%11 = udiv i32 %10, 1000000
%12 = add nuw i32 %4, %11
%13 = add i32 %12, 1
%14 = mul i32 %11, -1000000
%15 = add i32 %7, -1000000
%16 = add i32 %14, %15
store i32 %13, i32* %2
br label %17
17: ; preds = %9, %1
%18 = phi i32 [ %16, %9 ], [ %7, %1 ]
store i32 %18, i32* %5
ret void
}