#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*/ assert(int);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
int strlen(char *);
char *dbern_toenvstring_density(char *x, char **par, unsigned int npar,
                                int give_log) {
  char *prob, *buff;
  assert(par != NULL && npar >= 1);
  prob = par[0];
  buff = malloc(sizeof(char) * (strlen(x) * 2 + strlen(prob) * 2 + 40));
  if (give_log)
    sprintf(buff, "log((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))", x,
            prob, x, prob);
  else
    sprintf(buff, "((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))", x,
            prob, x, prob);
  return buff;
}


x86 assembly (clang, -O0):
<dbern_toenvstring_density>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     1170 <dbern_toenvstring_density+0x30>
cmpl   $0x1,-0x14(%rbp)
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x1,%ecx
add    %ecx,%eax
add    $0x28,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ed <dbern_toenvstring_density+0xad>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe1d(%rip),%rsi
call   1060 <sprintf@plt>
jmp    120d <dbern_toenvstring_density+0xcd>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xdfb(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbern_toenvstring_density>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
test   %rsi,%rsi
setne  %al
test   %edx,%edx
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    0x0(%rbp),%rbp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
lea    (%rax,%rax,1),%edi
add    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
lea    0xe6e(%rip),%rax
lea    0xe64(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %r15,%r8
mov    %rbp,%r9
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"log((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))\00"
@.str.1 = [53 x i8] c"((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))\00"
define i8* @dbern_toenvstring_density(i8* %0, i8** %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8**, i8*** %6
%12 = icmp ne i8** %11, null
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32, i32* %7
%15 = icmp uge i32 %14, 1
br label %16
16: ; preds = %13, %4
%17 = phi i1 [ false, %4 ], [ %15, %13 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
store i8* %22, i8** %9
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = mul nsw i32 %24, 2
%26 = load i8*, i8** %9
%27 = call i32 @strlen(i8* %26)
%28 = mul nsw i32 %27, 2
%29 = add nsw i32 %25, %28
%30 = add nsw i32 %29, 40
%31 = sext i32 %30 to i64
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %10
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %16
%38 = load i8*, i8** %10
%39 = load i8*, i8** %5
%40 = load i8*, i8** %9
%41 = load i8*, i8** %5
%42 = load i8*, i8** %9
%43 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %39, i8* %40, i8* %41, i8* %42)
br label %51
44: ; preds = %16
%45 = load i8*, i8** %10
%46 = load i8*, i8** %5
%47 = load i8*, i8** %9
%48 = load i8*, i8** %5
%49 = load i8*, i8** %9
%50 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47, i8* %48, i8* %49)
br label %51
51: ; preds = %44, %37
%52 = load i8*, i8** %10
ret i8* %52
}

LLVM IR (-O2):
@.str = [56 x i8] c"log((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))\00"
@.str.1 = [53 x i8] c"((%s) == 1.0 ? (%s) : ((%s) == 0.0 ? 1.0-(%s): 0.0))\00"
define noalias i8* @dbern_toenvstring_density(i8* %0, i8** %1, i32 %2, i32 %3) {
%5 = icmp ne i8** %1, null
%6 = icmp ne i32 %2, 0
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i8*, i8** %1
%11 = tail call i32 @strlen(i8* %0)
%12 = tail call i32 @strlen(i8* %10)
%13 = add i32 %12, %11
%14 = shl i32 %13, 1
%15 = add nsw i32 %14, 40
%16 = tail call i8* @malloc(i32 %15)
%17 = icmp eq i32 %3, 0
%18 = select i1 %17, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0)
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) %18, i8* %0, i8* %10, i8* %0, i8* %10)
ret i8* %16
}