#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 double uint64_t;
typedef double uint32_t;
typedef double int64_t;
typedef double int32_t;

/* Variables and functions */
int /*<<< orphan*/ gen_flo_test(char *, ...);
int /*<<< orphan*/ gen_int_test(char *, double *, int, double);
double rand_signed64();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  for (int i = 0; i < 4; i++) {
    int64_t i64 = rand_signed64();
    uint64_t u64 = (uint64_t)i64;
    if (i64 < 0)
      u64 = -i64;
    int32_t i32 = (int32_t)i64;
    uint32_t u32 = (uint32_t)u64;
    if (i32 < 0)
      u32 = -i32;
    gen_int_test("read-sfixed64", &i64, 64, i64);
    gen_int_test("read-fixed64 ", &u64, 64, u64);
    gen_int_test("read-sfixed32", &i32, 32, i32);
    gen_int_test("read-fixed32 ", &u32, 32, u32);
    double dbl = rand_signed64() / (double)rand_signed64() * 50000;
    float flt = dbl;
    gen_flo_test("read-double", &dbl, 64, dbl);
    gen_flo_test("read-float ", &flt, 32, flt);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    12f8 <main+0x1a8>
mov    $0x0,%al
call   1040 <rand_signed64@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c5 <main+0x75>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1208 <main+0xb8>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xdf4(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1070 <gen_int_test@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xde8(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   1070 <gen_int_test@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xddc(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x20,%edx
call   1070 <gen_int_test@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xdd0(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1070 <gen_int_test@plt>
mov    $0x0,%al
call   1040 <rand_signed64@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <rand_signed64@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xd69(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xd86(%rip),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x40,%edx
mov    $0x1,%al
call   1030 <gen_flo_test@plt>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd72(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x20,%edx
mov    $0x1,%al
call   1030 <gen_flo_test@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x26>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x4,%r14d
lea    0x8(%rsp),%r15
lea    0xeda(%rip),%r12
lea    0x28(%rsp),%r13
lea    0xeda(%rip),%rbx
lea    0x4(%rsp),%rbp
nop
xor    %eax,%eax
call   1040 <rand_signed64@plt>
movsd  %xmm0,0x30(%rsp)
movapd %xmm0,%xmm1
xorpd  0xe57(%rip),%xmm1
movapd %xmm0,%xmm2
cmpltsd 0xe62(%rip),%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movlpd %xmm2,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
movlpd %xmm2,0x8(%rsp)
lea    0xe45(%rip),%rdi
lea    0x30(%rsp),%rsi
mov    $0x40,%edx
call   1070 <gen_int_test@plt>
movsd  0x18(%rsp),%xmm0
lea    0xe37(%rip),%rdi
lea    0x18(%rsp),%rsi
mov    $0x40,%edx
call   1070 <gen_int_test@plt>
movsd  0x10(%rsp),%xmm0
lea    0xe29(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1070 <gen_int_test@plt>
movsd  0x8(%rsp),%xmm0
lea    0xe1b(%rip),%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1070 <gen_int_test@plt>
xor    %eax,%eax
call   1040 <rand_signed64@plt>
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1040 <rand_signed64@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
mulsd  0xdae(%rip),%xmm1
movsd  %xmm1,0x28(%rsp)
xorps  %xmm2,%xmm2
cvtsd2ss %xmm1,%xmm2
movaps %xmm1,%xmm0
movss  %xmm2,0x4(%rsp)
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x40,%edx
mov    $0x1,%al
call   1030 <gen_flo_test@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x20,%edx
mov    $0x1,%al
call   1030 <gen_flo_test@plt>
add    $0xffffffff,%r14d
jne    1190 <main+0x40>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"read-sfixed64\00"
@.str.1 = [14 x i8] c"read-fixed64 \00"
@.str.2 = [14 x i8] c"read-sfixed32\00"
@.str.3 = [14 x i8] c"read-fixed32 \00"
@.str.4 = [12 x i8] c"read-double\00"
@.str.5 = [12 x i8] c"read-float \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca float
store i32 0, i32* %1
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
store i32 0, i32* %2
br label %11
11: ; preds = %50, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %53
14: ; preds = %11
%15 = call double (...) @rand_signed64()
store double %15, double* %3
%16 = load double, double* %3
store double %16, double* %4
%17 = load double, double* %3
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load double, double* %3
%21 = fneg double %20
store double %21, double* %4
br label %22
22: ; preds = %19, %14
%23 = load double, double* %3
store double %23, double* %5
%24 = load double, double* %4
store double %24, double* %6
%25 = load double, double* %5
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load double, double* %5
%29 = fneg double %28
store double %29, double* %6
br label %30
30: ; preds = %27, %22
%31 = load double, double* %3
%32 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double* %3, i32 64, double %31)
%33 = load double, double* %4
%34 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %4, i32 64, double %33)
%35 = load double, double* %5
%36 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %5, i32 32, double %35)
%37 = load double, double* %6
%38 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double* %6, i32 32, double %37)
%39 = call double (...) @rand_signed64()
%40 = call double (...) @rand_signed64()
%41 = fdiv double %39, %40
%42 = fmul double %41, 5.000000e+04
store double %42, double* %7
%43 = load double, double* %7
%44 = fptrunc double %43 to float
store float %44, float* %8
%45 = load double, double* %7
%46 = call i32 (i8*, ...) @gen_flo_test(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double* %7, i32 64, double %45)
%47 = load float, float* %8
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @gen_flo_test(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), float* %8, i32 32, double %48)
br label %50
50: ; preds = %30
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %11
53: ; preds = %11
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [14 x i8] c"read-sfixed64\00"
@.str.1 = [14 x i8] c"read-fixed64 \00"
@.str.2 = [14 x i8] c"read-sfixed32\00"
@.str.3 = [14 x i8] c"read-fixed32 \00"
@.str.4 = [12 x i8] c"read-double\00"
@.str.5 = [12 x i8] c"read-float \00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca float
%7 = tail call i32 @time(i32* null)
%8 = tail call i32 @srand(i32 %7)
%9 = bitcast double* %1 to i8*
%10 = bitcast double* %2 to i8*
%11 = bitcast double* %3 to i8*
%12 = bitcast double* %4 to i8*
%13 = bitcast double* %5 to i8*
%14 = bitcast float* %6 to i8*
br label %16
15: ; preds = %16
ret i32 0
16: ; preds = %0, %16
%17 = phi i32 [ 0, %0 ], [ %38, %16 ]
%18 = call double (...) @rand_signed64()
store double %18, double* %1
%19 = fcmp olt double %18, 0.000000e+00
%20 = fneg double %18
%21 = select i1 %19, double %20, double %18
store double %21, double* %2
store double %18, double* %3
store double %21, double* %4
%22 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double* %1, i32 64, double %18)
%23 = load double, double* %2
%24 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %2, i32 64, double %23)
%25 = load double, double* %3
%26 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double* %3, i32 32, double %25)
%27 = load double, double* %4
%28 = call i32 @gen_int_test(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double* %4, i32 32, double %27)
%29 = call double (...) @rand_signed64()
%30 = call double (...) @rand_signed64()
%31 = fdiv double %29, %30
%32 = fmul double %31, 5.000000e+04
store double %32, double* %5
%33 = fptrunc double %32 to float
store float %33, float* %6
%34 = call i32 (i8*, ...) @gen_flo_test(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double* %5, i32 64, double %32)
%35 = load float, float* %6
%36 = fpext float %35 to double
%37 = call i32 (i8*, ...) @gen_flo_test(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), float* %6, i32 32, double %36)
%38 = add nuw nsw i32 %17, 1
%39 = icmp eq i32 %38, 4
br i1 %39, label %15, label %16
}