#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
scalar_t__ errno;
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int ft_random(void) {
  time_t ret;
  int seed;
  errno = 0;
  if ((ret = time(NULL)) <= 0 || errno)
    return (-1);
  srand(ret);
  if (errno)
    return (-1);
  seed = rand() % 2;
  if (errno)
    return (-1);
  return (seed);
}


x86 assembly (clang, -O0):
<ft_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    116c <ft_random+0x3c>
mov    0x2e7e(%rip),%rax
cmpq   $0x0,(%rax)
je     1178 <ft_random+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <ft_random+0xa2>
mov    -0x8(%rbp),%edi
call   1030 <srand@plt>
mov    0x2e59(%rip),%rax
cmpq   $0x0,(%rax)
je     119d <ft_random+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <ft_random+0xa2>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    0x2e2a(%rip),%rax
cmpq   $0x0,(%rax)
je     11cc <ft_random+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <ft_random+0xa2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_random>:
push   %r14
push   %rbx
push   %rax
mov    0x2ea5(%rip),%r14
movq   $0x0,(%r14)
xor    %edi,%edi
call   1040 <time@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jle    1180 <ft_random+0x50>
cmpq   $0x0,(%r14)
jne    1180 <ft_random+0x50>
mov    %eax,%edi
call   1030 <srand@plt>
cmpq   $0x0,(%r14)
jne    1180 <ft_random+0x50>
xor    %eax,%eax
call   1050 <rand@plt>
cmpq   $0x0,(%r14)
jne    1180 <ft_random+0x50>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @ft_random() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i64 0, i64* @errno
%4 = call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = icmp sle i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6, %0
store i32 -1, i32* %1
br label %24
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i32 @srand(i32 %11)
%13 = load i64, i64* @errno
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %1
br label %24
16: ; preds = %10
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 2
store i32 %18, i32* %3
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %1
br label %24
22: ; preds = %16
%23 = load i32, i32* %3
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %21, %15, %9
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @ft_random() {
store i64 0, i64* @errno
%1 = tail call i32 @time(i32* null)
%2 = icmp slt i32 %1, 1
%3 = load i64, i64* @errno
%4 = icmp ne i64 %3, 0
%5 = select i1 %2, i1 true, i1 %4
br i1 %5, label %16, label %6
6: ; preds = %0
%7 = tail call i32 @srand(i32 %1)
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = tail call i32 (...) @rand()
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = srem i32 %11, 2
br label %16
16: ; preds = %10, %6, %0, %14
%17 = phi i32 [ %15, %14 ], [ -1, %0 ], [ -1, %6 ], [ -1, %10 ]
ret i32 %17
}