#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  long tv_sec;
  long tv_usec;
};
struct TYPE_3__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double modf(double, double *);
int /*<<< orphan*/ perror(char *);
int setitimer(int /*<<< orphan*/, struct itimerval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void SetTimeout(double timeout_secs) {
  if (timeout_secs <= 0) {
    return;
  }
  double int_val, fraction_val;
  fraction_val = modf(timeout_secs, &int_val);
  struct itimerval timer = {.it_interval.tv_sec = 0,
                            .it_interval.tv_usec = 0,
                            .it_value.tv_sec = (long)int_val,
                            .it_value.tv_usec = (long)(fraction_val * 1e6)};
  if ((setitimer(ITIMER_REAL, &timer, NULL)) == -1) {
    fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/"
                    "heads/master/src/main/tools/process-tools.c"
                    ":"
                    "125"
                    ": ");
    perror("setitimer(ITIMER_REAL, &timer, NULL)");
    exit(EXIT_FAILURE);
  };
}


x86 assembly (clang, -O0):
<SetTimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1170 <SetTimeout+0x20>
jmp    11ff <SetTimeout+0xaf>
movsd  -0x8(%rbp),%xmm0
lea    -0x10(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  0xe6b(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <setitimer@plt>
cmp    $0xffffffff,%eax
jne    11ff <SetTimeout+0xaf>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xebf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetTimeout>:
sub    $0x28,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    11a9 <SetTimeout+0x59>
lea    0x8(%rsp),%rdi
call   1030 <modf@plt>
cvttsd2si 0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
mulsd  0xe84(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <setitimer@plt>
cmp    $0xffffffff,%eax
je     11ae <SetTimeout+0x5e>
add    $0x28,%rsp
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xee1(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@stderr = global i32 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/process-tools.c:125: \00"
@.str.1 = [37 x i8] c"setitimer(ITIMER_REAL, &timer, NULL)\00"
@EXIT_FAILURE = global i32 0
define void @SetTimeout(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca %struct.itimerval
store double %0, double* %2
%6 = load double, double* %2
%7 = fcmp ole double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
br label %32
9: ; preds = %1
%10 = load double, double* %2
%11 = call double @modf(double %10, double* %3)
store double %11, double* %4
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = load double, double* %3
%15 = fptosi double %14 to i64
store i64 %15, i64* %13
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 1
%17 = load double, double* %4
%18 = fmul double %17, 1.000000e+06
%19 = fptosi double %18 to i64
store i64 %19, i64* %16
%20 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %5, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 0
store i32 0, i32* %21
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 1
store i32 0, i32* %22
%23 = load i32, i32* @ITIMER_REAL
%24 = call i32 @setitimer(i32 %23, %struct.itimerval* %5, i32* null)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %9
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %8, %9
ret void
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32, i32 }
@ITIMER_REAL = global i32 0
@stderr = global i32 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/process-tools.c:125: \00"
@.str.1 = [37 x i8] c"setitimer(ITIMER_REAL, &timer, NULL)\00"
@EXIT_FAILURE = global i32 0
define void @SetTimeout(double %0) {
%2 = alloca double
%3 = alloca %struct.itimerval
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %5, label %27
5: ; preds = %1
%6 = bitcast double* %2 to i8*
%7 = call double @modf(double %0, double* %2)
%8 = bitcast %struct.itimerval* %3 to i8*
%9 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%10 = load double, double* %2
%11 = fptosi double %10 to i64
store i64 %11, i64* %9
%12 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
%13 = fmul double %7, 1.000000e+06
%14 = fptosi double %13 to i64
store i64 %14, i64* %12
%15 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 0
store i32 0, i32* %15
%16 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 1
store i32 0, i32* %16
%17 = load i32, i32* @ITIMER_REAL
%18 = call i32 @setitimer(i32 %17, %struct.itimerval* %3, i32* null)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %5
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %5
br label %27
27: ; preds = %1, %26
ret void
}