#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*/ snprintf(char *, size_t const, char *, ...);
size_t strlen(char *);
size_t fillin_csv_column(const double val, char data[], const size_t sz_data,
                         const int is_monitored, const int is_column_present) {
  size_t offset = 0;
  if (is_monitored) {
    snprintf(data, sz_data - 1, ",%.1f", val);
    offset = strlen(data);
  } else if (is_column_present) {
    snprintf(data, sz_data - 1, ",");
    offset = strlen(data);
  }
  return offset;
}


x86 assembly (clang, -O0):
<fillin_csv_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117e <fillin_csv_column+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
movsd  -0x8(%rbp),%xmm0
lea    0xe9b(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    11b4 <fillin_csv_column+0x94>
cmpl   $0x0,-0x20(%rbp)
je     11af <fillin_csv_column+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
lea    0xe6b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    11b4 <fillin_csv_column+0x94>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillin_csv_column>:
push   %rbx
mov    %rdi,%rbx
test   %edx,%edx
je     113f <fillin_csv_column+0x1f>
add    $0xffffffffffffffff,%rsi
lea    0xecd(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <snprintf@plt>
jmp    1158 <fillin_csv_column+0x38>
test   %ecx,%ecx
je     1161 <fillin_csv_column+0x41>
add    $0xffffffffffffffff,%rsi
lea    0xeb8(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strlen@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c",%.1f\00"
@.str.1 = [2 x i8] c",\00"
define i64 @fillin_csv_column(double %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca double
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store double %0, double* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i64 0, i64* %11
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %5
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = sub i64 %16, 1
%18 = load double, double* %6
%19 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %15, i64 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %18)
%20 = load i8*, i8** %7
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %11
br label %33
22: ; preds = %5
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = load i64, i64* %8
%28 = sub i64 %27, 1
%29 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %26, i64 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %30)
store i64 %31, i64* %11
br label %32
32: ; preds = %25, %22
br label %33
33: ; preds = %32, %14
%34 = load i64, i64* %11
ret i64 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c",%.1f\00"
@.str.1 = [2 x i8] c",\00"
define i64 @fillin_csv_column(double %0, i8* nocapture %1, i64 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %3, 0
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = add i64 %2, -1
%9 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %0)
br label %15
10: ; preds = %5
%11 = icmp eq i32 %4, 0
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = add i64 %2, -1
%14 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %7, %12
%16 = tail call i64 @strlen(i8* dereferenceable(1) %1)
br label %17
17: ; preds = %15, %10
%18 = phi i64 [ 0, %10 ], [ %16, %15 ]
ret i64 %18
}