#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 *, int, char *, float);
int /*<<< orphan*/ strncpy(char *, char *, int);
void strfloat_or_null(char *str, int len, int a, int b) {
  if (!str) {
    return;
  }
  if (b) {
    snprintf(str, len, "%.3f", (float)a / (float)b);
  } else {
    strncpy(str, "NULL", len);
  }
}


x86 assembly (clang, -O0):
<strfloat_or_null>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1145 <strfloat_or_null+0x25>
jmp    1188 <strfloat_or_null+0x68>
cmpl   $0x0,-0x14(%rbp)
je     1175 <strfloat_or_null+0x55>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
lea    0xe95(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1188 <strfloat_or_null+0x68>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe82(%rip),%rsi
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfloat_or_null>:
test   %rdi,%rdi
je     1145 <strfloat_or_null+0x25>
mov    %esi,%eax
test   %ecx,%ecx
je     1146 <strfloat_or_null+0x26>
cvtsi2ss %edx,%xmm0
cvtsi2ss %ecx,%xmm1
divss  %xmm1,%xmm0
lea    0xec2(%rip),%rdx
mov    %eax,%esi
jmp    1040 <snprintf@plt>
ret
lea    0xeb8(%rip),%rsi
mov    %eax,%edx
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%.3f\00"
@.str.1 = [5 x i8] c"NULL\00"
define void @strfloat_or_null(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %4
br label %28
12: ; preds = %4
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = sitofp i32 %18 to float
%20 = load i32, i32* %8
%21 = sitofp i32 %20 to float
%22 = fdiv float %19, %21
%23 = call i32 @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %22)
br label %28
24: ; preds = %12
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 @strncpy(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %11, %24, %15
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.3f\00"
@.str.1 = [5 x i8] c"NULL\00"
define void @strfloat_or_null(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %15, label %6
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br i1 %7, label %13, label %8
8: ; preds = %6
%9 = sitofp i32 %2 to float
%10 = sitofp i32 %3 to float
%11 = fdiv float %9, %10
%12 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %11)
br label %15
13: ; preds = %6
%14 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %15
15: ; preds = %4, %13, %8
ret void
}