#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 */

/* Variables and functions */
int M_PI;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int rand();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stdout;
int time(int /*<<< orphan*/ *);
double *new_angle_set(int n, int seed) {
  double *angles;
  int k;
  if ((angles = (double *)malloc(n * sizeof(double))) == NULL)
    return NULL;
  if (seed == 0) {
    int s = time(NULL);
    srand(s);
    fprintf(stdout, "using seed %d\n", s);
  } else {
    srand(seed);
  }
  for (k = 0; k < n; k++) {
    angles[k] = (rand() % 360) * M_PI / 180;
  }
  return angles;
}


x86 assembly (clang, -O0):
<new_angle_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1188 <new_angle_set+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1228 <new_angle_set+0xd8>
cmpl   $0x0,-0x10(%rbp)
jne    11c3 <new_angle_set+0x73>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <srand@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11cb <new_angle_set+0x7b>
mov    -0x10(%rbp),%edi
call   1030 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1220 <new_angle_set+0xd0>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x168,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    0x2df2(%rip),%rcx
imul   (%rcx),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d2 <new_angle_set+0x82>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_angle_set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1186 <new_angle_set+0x36>
mov    %rax,%r15
test   %ebp,%ebp
je     118e <new_angle_set+0x3e>
mov    %ebp,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jg     11ba <new_angle_set+0x6a>
jmp    122b <new_angle_set+0xdb>
xor    %r15d,%r15d
jmp    122b <new_angle_set+0xdb>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
test   %r14d,%r14d
jle    122b <new_angle_set+0xdb>
mov    %r14d,%ebp
mov    0x2e24(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x8,%ecx
add    %edx,%ecx
imul   $0x168,%ecx,%ecx
sub    %ecx,%eax
imul   (%r14),%eax
cltq
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x7,%eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <new_angle_set+0x80>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [15 x i8] c"using seed %d\0A\00"
@M_PI = global i32 0
define double* @new_angle_set(i32 %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %6
%15 = icmp eq double* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store double* null, double** %3
br label %51
17: ; preds = %2
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = call i32 @time(i32* null)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = call i32 @srand(i32 %22)
%24 = load i32, i32* @stdout
%25 = load i32, i32* %8
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %17
%28 = load i32, i32* %5
%29 = call i32 @srand(i32 %28)
br label %30
30: ; preds = %27, %20
store i32 0, i32* %7
br label %31
31: ; preds = %46, %30
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 360
%38 = load i32, i32* @M_PI
%39 = mul nsw i32 %37, %38
%40 = sdiv i32 %39, 180
%41 = sitofp i32 %40 to double
%42 = load double*, double** %6
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
store double %41, double* %45
br label %46
46: ; preds = %35
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %31
49: ; preds = %31
%50 = load double*, double** %6
store double* %50, double** %3
br label %51
51: ; preds = %49, %16
%52 = load double*, double** %3
ret double* %52
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [15 x i8] c"using seed %d\0A\00"
@M_PI = global i32 0
define double* @new_angle_set(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = icmp eq i64 %4, 0
br i1 %6, label %31, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = tail call i32 @time(i32* null)
%11 = tail call i32 @srand(i32 %10)
%12 = load i32, i32* @stdout
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %16
14: ; preds = %7
%15 = tail call i32 @srand(i32 %1)
br label %16
16: ; preds = %14, %9
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = zext i32 %0 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %29, %20 ]
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 360
%24 = load i32, i32* @M_PI
%25 = mul nsw i32 %23, %24
%26 = sdiv i32 %25, 180
%27 = sitofp i32 %26 to double
%28 = getelementptr inbounds double, double* %5, i64 %21
store double %27, double* %28
%29 = add nuw nsw i64 %21, 1
%30 = icmp eq i64 %29, %19
br i1 %30, label %31, label %20
31: ; preds = %20, %16, %2
%32 = phi double* [ null, %2 ], [ %5, %16 ], [ %5, %20 ]
ret double* %32
}