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

/* Variables and functions */
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, long);
void get_cur_time(void) {
  struct timeval tv;
  int ret;
  ret = gettimeofday(&tv, NULL);
  if (ret) {
    perror("gettimeofday");
  } else {
    printf("seconds=%ld useconds=%ld\n", (long)tv.tv_sec, (long)tv.tv_usec);
  }
}


x86 assembly (clang, -O0):
<get_cur_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1163 <get_cur_time+0x33>
lea    0xea7(%rip),%rdi
call   1050 <perror@plt>
jmp    1177 <get_cur_time+0x47>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cur_time>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %eax,%eax
jne    115e <get_cur_time+0x2e>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
lea    0xeb8(%rip),%rdi
add    $0x18,%rsp
jmp    1030 <printf@plt>
lea    0xe9b(%rip),%rdi
add    $0x18,%rsp
jmp    1050 <perror@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [26 x i8] c"seconds=%ld useconds=%ld\0A\00"
define void @get_cur_time() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%12 = load i64, i64* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %10, i64 %12)
br label %14
14: ; preds = %8, %6
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [26 x i8] c"seconds=%ld useconds=%ld\0A\00"
define void @get_cur_time() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
7: ; preds = %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %9, i64 %11)
br label %13
13: ; preds = %7, %5
ret void
}