#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int sprintf(char *, char *, float const);
int /*<<< orphan*/ *strstr(char *, char *);
void write_num(FILE *fp, const float num) {
  char buf[32];
  int last = sprintf(buf,
                     "%"
                     "g",
                     num) -
             1;
  if (strstr(buf, ".") != NULL) {
    while (buf[last] == '0')
      last--;
    if (buf[last] == '.')
      last--;
    buf[last + 1] = 0;
  }
  fprintf(fp, "%s", buf);
}


x86 assembly (clang, -O0):
<write_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
lea    0xeaf(%rip),%rsi
call   1040 <sprintf@plt>
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11c3 <write_num+0x93>
jmp    117b <write_num+0x4b>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jne    119b <write_num+0x6b>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <write_num+0x4b>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x2e,%eax
jne    11b6 <write_num+0x86>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe33(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_num>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
lea    0xebe(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118f <write_num+0x5f>
movslq %ebp,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rax,1),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x30,%cl
je     1170 <write_num+0x40>
cmp    $0x2e,%cl
je     1186 <write_num+0x56>
add    $0x1,%rax
add    $0x1,%eax
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%g\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"%s\00"
define void @write_num(i32* %0, float %1) {
%3 = alloca i32*
%4 = alloca float
%5 = alloca [32 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store float %1, float* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = load float, float* %4
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %6
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = call i32* @strstr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %40
14: ; preds = %2
br label %15
15: ; preds = %22, %14
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 48
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* %6
%24 = add nsw i32 %23, -1
store i32 %24, i32* %6
br label %15
25: ; preds = %15
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 46
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %35
35: ; preds = %32, %25
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35, %2
%41 = load i32*, i32** %3
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%43 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %42)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%g\00"
define void @write_num(i32* nocapture %0, float %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), float %1)
%6 = call i8* @strchr(i8* %4, i32 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %2
%9 = sext i32 %5 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %9, %8 ], [ %12, %10 ]
%12 = add i64 %11, -1
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 48, label %10
i8 46, label %15
]
15: ; preds = %10
%16 = add i64 %11, -2
br label %17
17: ; preds = %10, %15
%18 = phi i64 [ %16, %15 ], [ %12, %10 ]
%19 = shl i64 %18, 32
%20 = add i64 %19, 4294967296
%21 = ashr exact i64 %20, 32
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %17, %2
%24 = call i32 @fputs(i8* %4, i32* %0)
ret void
}