#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 *);
double 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, small = 1e-5;
  xtoy(pi, p, 4);
  for (i = 1; i < 4; i++)
    p[i] += p[i - 1];
  if (fabs(p[3] - 1) > small)
    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)
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1050 <xtoy@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    119f <dnamaker+0x6f>
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    1169 <dnamaker+0x39>
movsd  -0x28(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe59(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    11d2 <dnamaker+0xa2>
lea    0xe53(%rip),%rdi
call   1030 <error2@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1251 <dnamaker+0x121>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rndu@plt>
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    1233 <dnamaker+0x103>
movsd  -0x48(%rbp),%xmm1
movslq -0x20(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1220 <dnamaker+0xf0>
jmp    1233 <dnamaker+0x103>
jmp    1225 <dnamaker+0xf5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f8 <dnamaker+0xc8>
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    11d9 <dnamaker+0xa9>
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   1050 <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  0xe80(%rip),%xmm0
andpd  0xe88(%rip),%xmm0
ucomisd 0xe78(%rip),%xmm0
jbe    119e <dnamaker+0x6e>
lea    0xe87(%rip),%rdi
call   1030 <error2@plt>
test   %ebp,%ebp
jle    1203 <dnamaker+0xd3>
mov    %ebp,%r15d
xor    %ebx,%ebx
jmp    11bd <dnamaker+0x8d>
nopl   0x0(%rax)
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1203 <dnamaker+0xd3>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <rndu@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x80>
movsd  0x8(%rsp),%xmm1
mov    $0x1,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x80>
movsd  0x10(%rsp),%xmm1
mov    $0x2,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x80>
movsd  0x18(%rsp),%xmm1
mov    $0x3,%bpl
ucomisd %xmm0,%xmm1
ja     11b0 <dnamaker+0x80>
mov    $0x4,%bpl
jmp    11b0 <dnamaker+0x80>
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
%11 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store double* %2, double** %6
store double 1.000000e-05, double* %11
%12 = load double*, double** %6
%13 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%14 = call i32 @xtoy(double* %12, double* %13, i32 4)
store i32 1, i32* %7
br label %15
15: ; preds = %29, %3
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i32, i32* %7
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %21
%23 = load double, double* %22
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %25
%27 = load double, double* %26
%28 = fadd double %27, %23
store double %28, double* %26
br label %29
29: ; preds = %18
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %15
32: ; preds = %15
%33 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 3
%34 = load double, double* %33
%35 = fsub double %34, 1.000000e+00
%36 = call double @llvm.fabs.f64(double %35)
%37 = load double, double* %11
%38 = fcmp ogt double %36, %37
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 @error2(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %39, %32
store i32 0, i32* %7
br label %42
42: ; preds = %70, %41
%43 = load i32, i32* %7
%44 = load i32, i32* %5
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %73
46: ; preds = %42
store i32 0, i32* %8
%47 = call double (...) @rndu()
store double %47, double* %10
br label %48
48: ; preds = %60, %46
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 4
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = load double, double* %10
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 %54
%56 = load double, double* %55
%57 = fcmp olt double %52, %56
br i1 %57, label %58, label %59
58: ; preds = %51
br label %63
59: ; preds = %51
br label %60
60: ; preds = %59
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %48
63: ; preds = %58, %48
%64 = load i32, i32* %8
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %4
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 %65, i8* %69
br label %70
70: ; preds = %63
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %42
73: ; preds = %42
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 double @llvm.fabs.f64(double %18)
%20 = fcmp ogt double %19, 1.000000e-05
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
}