#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 */
float log(float);
int Transform_log(float *p, int n, float lim) {
  int i;
  for (i = 0; i < n; i++)
    if (p[i] == 0)
      p[i] = log(lim);
    else
      p[i] = log(p[i]);
  return (1);
}


x86 assembly (clang, -O0):
<Transform_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <Transform_log+0x94>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1172 <Transform_log+0x62>
jp     1172 <Transform_log+0x62>
movss  -0x10(%rbp),%xmm0
call   1030 <log@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    1191 <Transform_log+0x81>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <log@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    1196 <Transform_log+0x86>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <Transform_log+0x1b>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Transform_log>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1166 <Transform_log+0x56>
movaps %xmm0,%xmm3
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
movaps %xmm0,(%rsp)
nopl   0x0(%rax)
movss  (%r15,%rbx,4),%xmm1
movaps %xmm1,%xmm0
cmpeqss 0xebe(%rip),%xmm0
movaps %xmm0,%xmm2
andnps %xmm1,%xmm2
andps  %xmm3,%xmm0
orps   %xmm2,%xmm0
call   1030 <log@plt>
movaps (%rsp),%xmm3
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <Transform_log+0x20>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @Transform_log(float* %0, i32 %1, float %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
store float* %0, float** %4
store i32 %1, i32* %5
store float %2, float* %6
store i32 0, i32* %7
br label %8
8: ; preds = %38, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load float*, float** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds float, float* %13, i64 %15
%17 = load float, float* %16
%18 = fcmp oeq float %17, 0.000000e+00
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load float, float* %6
%21 = call float @log(float %20)
%22 = load float*, float** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %22, i64 %24
store float %21, float* %25
br label %37
26: ; preds = %12
%27 = load float*, float** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
%31 = load float, float* %30
%32 = call float @log(float %31)
%33 = load float*, float** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds float, float* %33, i64 %35
store float %32, float* %36
br label %37
37: ; preds = %26, %19
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %8
41: ; preds = %8
ret i32 1
}

LLVM IR (-O2):
define i32 @Transform_log(float* nocapture %0, i32 %1, float %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %14, %7 ]
%9 = getelementptr inbounds float, float* %0, i64 %8
%10 = load float, float* %9
%11 = fcmp oeq float %10, 0.000000e+00
%12 = select i1 %11, float %2, float %10
%13 = tail call float @log(float %12)
store float %13, float* %9
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %7
16: ; preds = %7, %3
ret i32 1
}