#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 /*<<< orphan*/ error2(char *);
int fabs(double);
double rndu();
int /*<<< orphan*/ xtoy(double *, double *, int);
int dnamaker(char z[], int ls, double pi[]) {
  int i, j;
  double p[4], r;
  xtoy(pi, p, 4);
  for (i = 1; i < 4; i++)
    p[i] += p[i - 1];
  if (fabs(p[3] - 1) > 1e-5)
    error2("sum pi != 1..");
  for (i = 0; i < ls; i++) {
    for (j = 0, r = rndu(); j < 4; j++)
      if (r < p[j])
        break;
    z[i] = (char)j;
  }
  return (0);
}


x86 assembly (clang, -O0):
<dnamaker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1060 <xtoy@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11a2 <dnamaker+0x62>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x40(%rbp,%rax,8),%xmm0
movslq -0x1c(%rbp),%rax
addsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116c <dnamaker+0x2c>
movsd  -0x28(%rbp),%xmm0
movsd  0xe59(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe3c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11da <dnamaker+0x9a>
lea    0xe3b(%rip),%rdi
call   1030 <error2@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1259 <dnamaker+0x119>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <rndu@plt>
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    123b <dnamaker+0xfb>
movsd  -0x48(%rbp),%xmm1
movslq -0x20(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1228 <dnamaker+0xe8>
jmp    123b <dnamaker+0xfb>
jmp    122d <dnamaker+0xed>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1200 <dnamaker+0xc0>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e1 <dnamaker+0xa1>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnamaker>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %rdx,%rdi
mov    $0x4,%edx
call   1060 <xtoy@plt>
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
addsd  0xe70(%rip),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    11a5 <dnamaker+0x65>
lea    0xe68(%rip),%rdi
call   1030 <error2@plt>
test   %ebp,%ebp
jle    1203 <dnamaker+0xc3>
mov    %ebp,%r15d
xor    %ebx,%ebx
jmp    11bd <dnamaker+0x7d>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1203 <dnamaker+0xc3>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <rndu@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x70>
movsd  0x8(%rsp),%xmm1
mov    $0x1,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x70>
movsd  0x10(%rsp),%xmm1
mov    $0x2,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x70>
movsd  0x18(%rsp),%xmm1
mov    $0x3,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x70>
mov    $0x4,%bpl
jmp    11b0 <dnamaker+0x70>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"sum pi != 1..\00"
define i32 @dnamaker(i8* %0, i32 %1, double* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x double]
%10 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store double* %2, double** %6
%11 = load double*, double** %6
%12 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%13 = call i32 @xtoy(double* %11, double* %12, i32 4)
store i32 1, i32* %7
br label %14
14: ; preds = %28, %3
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %20
%22 = load double, double* %21
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %24
%26 = load double, double* %25
%27 = fadd double %26, %22
store double %27, double* %25
br label %28
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %14
31: ; preds = %14
%32 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 3
%33 = load double, double* %32
%34 = fsub double %33, 1.000000e+00
%35 = call i32 @fabs(double %34)
%36 = sitofp i32 %35 to double
%37 = fcmp ogt double %36, 1.000000e-05
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @error2(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
store i32 0, i32* %7
br label %41
41: ; preds = %69, %40
%42 = load i32, i32* %7
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %72
45: ; preds = %41
store i32 0, i32* %8
%46 = call double (...) @rndu()
store double %46, double* %10
br label %47
47: ; preds = %59, %45
%48 = load i32, i32* %8
%49 = icmp slt i32 %48, 4
br i1 %49, label %50, label %62
50: ; preds = %47
%51 = load double, double* %10
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %53
%55 = load double, double* %54
%56 = fcmp olt double %51, %55
br i1 %56, label %57, label %58
57: ; preds = %50
br label %62
58: ; preds = %50
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %47
62: ; preds = %57, %47
%63 = load i32, i32* %8
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %4
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 %64, i8* %68
br label %69
69: ; preds = %62
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %41
72: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"sum pi != 1..\00"
define i32 @dnamaker(i8* nocapture writeonly %0, i32 %1, double* %2) {
%4 = alloca [4 x double]
%5 = bitcast [4 x double]* %4 to i8*
%6 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%7 = call i32 @xtoy(double* %2, double* %6, i32 4)
%8 = load double, double* %6
%9 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%10 = load double, double* %9
%11 = fadd double %8, %10
store double %11, double* %9
%12 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%13 = load double, double* %12
%14 = fadd double %11, %13
store double %14, double* %12
%15 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%16 = load double, double* %15
%17 = fadd double %14, %16
store double %17, double* %15
%18 = fadd double %17, -1.000000e+00
%19 = call i32 @fabs(double %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @error2(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = icmp sgt i32 %1, 0
br i1 %24, label %25, label %47
25: ; preds = %23
%26 = zext i32 %1 to i64
br label %27
27: ; preds = %25, %42
%28 = phi i64 [ 0, %25 ], [ %45, %42 ]
%29 = call double (...) @rndu()
%30 = load double, double* %6
%31 = fcmp olt double %29, %30
br i1 %31, label %42, label %32
32: ; preds = %27
%33 = load double, double* %9
%34 = fcmp olt double %29, %33
br i1 %34, label %42, label %35
35: ; preds = %32
%36 = load double, double* %12
%37 = fcmp olt double %29, %36
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load double, double* %15
%40 = fcmp olt double %29, %39
br i1 %40, label %42, label %41
41: ; preds = %38
br label %42
42: ; preds = %41, %38, %35, %32, %27
%43 = phi i8 [ 0, %27 ], [ 1, %32 ], [ 2, %35 ], [ 3, %38 ], [ 4, %41 ]
%44 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 %43, i8* %44
%45 = add nuw nsw i64 %28, 1
%46 = icmp eq i64 %45, %26
br i1 %46, label %47, label %27
47: ; preds = %42, %23
ret i32 0
}