#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 timezone {
  int dummy;
};
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ abort_safe_block();
int /*<<< orphan*/ errno;
int gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ tap_error_errno_at(char *, int /*<<< orphan*/, char *, int);
int safe_gettimeofday(struct timeval *restrict tv, struct timezone *tz) {
  int res = gettimeofday(tv, tz);
  if (res < 0) {
    tap_error_errno_at(
        ("gettimeofday()"), (errno),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/picotm/picotm/refs/heads/master/tests/"
        "libsafeblk/safe_sys_time.c",
        31);
    abort_safe_block();
  }
  return res;
}


x86 assembly (clang, -O0):
<safe_gettimeofday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1182 <safe_gettimeofday+0x52>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdi
lea    0xe9e(%rip),%rdx
mov    $0x1f,%ecx
call   1050 <tap_error_errno_at@plt>
mov    $0x0,%al
call   1030 <abort_safe_block@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_gettimeofday>:
push   %rbx
call   1040 <gettimeofday@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1164 <safe_gettimeofday+0x34>
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
lea    0xebc(%rip),%rdx
mov    $0x1f,%ecx
call   1050 <tap_error_errno_at@plt>
xor    %eax,%eax
call   1030 <abort_safe_block@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [15 x i8] c"gettimeofday()\00"
@errno = global i32 0
@.str.1 = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/picotm/picotm/refs/heads/master/tests/libsafeblk/safe_sys_time.c\00"
define i32 @safe_gettimeofday(%struct.timeval* noalias %0, %struct.timezone* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timezone*
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timezone* %1, %struct.timezone** %4
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = load %struct.timezone*, %struct.timezone** %4
%8 = call i32 @gettimeofday(%struct.timeval* %6, %struct.timezone* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @tap_error_errno_at(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str.1, i64 0, i64 0), i32 31)
%14 = call i32 (...) @abort_safe_block()
br label %15
15: ; preds = %11, %2
%16 = load i32, i32* %5
ret i32 %16
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i32 }
@.str = [15 x i8] c"gettimeofday()\00"
@errno = global i32 0
@.str.1 = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/picotm/picotm/refs/heads/master/tests/libsafeblk/safe_sys_time.c\00"
define i32 @safe_gettimeofday(%struct.timeval* noalias nocapture %0, %struct.timezone* nocapture %1) {
%3 = tail call i32 @gettimeofday(%struct.timeval* %0, %struct.timezone* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @tap_error_errno_at(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6, i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str.1, i64 0, i64 0), i32 31)
%8 = tail call i32 (...) @abort_safe_block()
br label %9
9: ; preds = %5, %2
ret i32 %3
}