#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 */
scalar_t__ format_timeval(struct timeval *, char *, size_t);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int get_timestamp(char *buf, size_t size) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) != 0) {
    perror("gettimeofday");
    return 1;
  }
  if (format_timeval(&tv, buf, size) < 0) {
    perror("format error");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     116f <get_timestamp+0x3f>
lea    0xea2(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <get_timestamp+0x79>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
call   1030 <format_timeval@plt>
cmp    $0x0,%rax
jge    11a2 <get_timestamp+0x72>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <get_timestamp+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    1175 <get_timestamp+0x45>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <format_timeval@plt>
test   %rax,%rax
js     117e <get_timestamp+0x4e>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe84(%rip),%rdi
jmp    1185 <get_timestamp+0x55>
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%r14d
jmp    1168 <get_timestamp+0x38>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [13 x i8] c"format error\00"
define i32 @get_timestamp(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.timeval
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %19
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i64 @format_timeval(%struct.timeval* %6, i8* %12, i64 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %19
18: ; preds = %11
store i32 0, i32* %3
br label %19
19: ; preds = %18, %16, %9
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [13 x i8] c"format error\00"
define i32 @get_timestamp(i8* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %14
9: ; preds = %2
%10 = call i64 @format_timeval(%struct.timeval* %3, i8* %0, i64 %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %9, %12, %7
%15 = phi i32 [ 1, %7 ], [ 1, %12 ], [ 0, %9 ]
ret i32 %15
}