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

/* Variables and functions */
int EPERM;
scalar_t__ errno;
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ logError(char *, int, scalar_t__, char *);
int /*<<< orphan*/ srand(int);
char *strerror(scalar_t__);
int set_rand_seed() {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) != 0) {
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "call gettimeofday fail, "
             "errno=%d, error info: %s",
             1851, errno,
             (strerror(errno) != NULL ? strerror(errno) : "Unkown error"));
    return errno != 0 ? errno : EPERM;
  }
  srand(tv.tv_sec ^ tv.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<set_rand_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     1205 <set_rand_seed+0xc5>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
cmp    $0x0,%rax
je     119e <set_rand_seed+0x5e>
mov    0x2e53(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    %rax,-0x20(%rbp)
jmp    11ae <set_rand_seed+0x6e>
lea    0xf3c(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ae <set_rand_seed+0x6e>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe43(%rip),%rdi
mov    $0x73b,%esi
call   1040 <logError@plt>
mov    0x2e12(%rip),%rax
cmpq   $0x0,(%rax)
je     11eb <set_rand_seed+0xab>
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11f9 <set_rand_seed+0xb9>
mov    0x2dde(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1217 <set_rand_seed+0xd7>
mov    -0x10(%rbp),%edi
xor    -0xc(%rbp),%edi
call   1050 <srand@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rand_seed>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
je     1179 <set_rand_seed+0x39>
mov    0x2e84(%rip),%r14
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1060 <strerror@plt>
test   %rax,%rax
je     1187 <set_rand_seed+0x47>
mov    (%r14),%rdi
call   1060 <strerror@plt>
mov    %rax,%rcx
jmp    118e <set_rand_seed+0x4e>
mov    0x4(%rsp),%edi
xor    (%rsp),%edi
call   1050 <srand@plt>
jmp    11b3 <set_rand_seed+0x73>
lea    0xf53(%rip),%rcx
lea    0xe6b(%rip),%rdi
mov    $0x73b,%esi
mov    %rbx,%rdx
call   1040 <logError@plt>
mov    (%r14),%rbx
test   %rbx,%rbx
jne    11b3 <set_rand_seed+0x73>
mov    0x2e1f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [225 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, call gettimeofday fail, errno=%d, error info: %s\00"
@errno = global i64 0
@.str.1 = [13 x i8] c"Unkown error\00"
@EPERM = global i32 0
define i32 @set_rand_seed() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @errno
%8 = call i8* @strerror(i64 %7)
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = call i8* @strerror(i64 %11)
br label %14
13: ; preds = %5
br label %14
14: ; preds = %13, %10
%15 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %13 ]
%16 = call i32 @logError(i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str, i64 0, i64 0), i32 1851, i64 %6, i8* %15)
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i64, i64* @errno
br label %24
21: ; preds = %14
%22 = load i32, i32* @EPERM
%23 = sext i32 %22 to i64
br label %24
24: ; preds = %21, %19
%25 = phi i64 [ %20, %19 ], [ %23, %21 ]
%26 = trunc i64 %25 to i32
store i32 %26, i32* %1
br label %34
27: ; preds = %0
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%31 = load i32, i32* %30
%32 = xor i32 %29, %31
%33 = call i32 @srand(i32 %32)
store i32 0, i32* %1
br label %34
34: ; preds = %27, %24
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [225 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, call gettimeofday fail, errno=%d, error info: %s\00"
@errno = global i64 0
@.str.1 = [13 x i8] c"Unkown error\00"
@EPERM = global i32 0
define i32 @set_rand_seed() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = tail call i8* @strerror(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = load i64, i64* @errno
%11 = tail call i8* @strerror(i64 %10)
br label %12
12: ; preds = %5, %9
%13 = phi i8* [ %11, %9 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %5 ]
%14 = tail call i32 @logError(i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str, i64 0, i64 0), i32 1851, i64 %6, i8* %13)
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* @EPERM
%18 = zext i32 %17 to i64
%19 = select i1 %16, i64 %18, i64 %15
%20 = trunc i64 %19 to i32
br label %28
21: ; preds = %0
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%25 = load i32, i32* %24
%26 = xor i32 %25, %23
%27 = tail call i32 @srand(i32 %26)
br label %28
28: ; preds = %21, %12
%29 = phi i32 [ %20, %12 ], [ 0, %21 ]
ret i32 %29
}