#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*/ sprintf(char *, char *, double);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *fmt(double g) {
  static char buf[10][30];
  static int n;
  char *p;
  p = buf[n++];
  if (n == 10)
    n = 0;
  sprintf(p, "%g", g);
  if (strcmp(p, "-0") == 0)
    strcpy(p, "negzero");
  return p;
}


x86 assembly (clang, -O0):
<fmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    0x3039(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x302e(%rip)
movslq %eax,%rcx
lea    0x2ef8(%rip),%rax
imul   $0x1e,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0xa,0x3012(%rip)
jne    117a <fmt+0x4a>
movl   $0x0,0x3002(%rip)
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe76(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b9 <fmt+0x89>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt>:
push   %rbx
movslq 0x3044(%rip),%rax
lea    0x1(%rax),%ecx
mov    %rax,%rdx
shl    $0x5,%rdx
sub    %rax,%rdx
sub    %rax,%rdx
lea    0x2f01(%rip),%rbx
add    %rdx,%rbx
xor    %eax,%eax
cmp    $0xa,%ecx
cmovne %ecx,%eax
mov    %eax,0x301c(%rip)
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1192 <fmt+0x62>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@fmt.buf = internal global [10 x [30 x i8]] zeroinitializer
@fmt.n = internal global i32 0
@.str = [3 x i8] c"%g\00"
@.str.1 = [3 x i8] c"-0\00"
@.str.2 = [8 x i8] c"negzero\00"
define i8* @fmt(double %0) {
%2 = alloca double
%3 = alloca i8*
store double %0, double* %2
%4 = load i32, i32* @fmt.n
%5 = add nsw i32 %4, 1
store i32 %5, i32* @fmt.n
%6 = sext i32 %4 to i64
%7 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* @fmt.buf, i64 0, i64 %6
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
store i8* %8, i8** %3
%9 = load i32, i32* @fmt.n
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* @fmt.n
br label %12
12: ; preds = %11, %1
%13 = load i8*, i8** %3
%14 = load double, double* %2
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load i8*, i8** %3
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %12
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@fmt.buf = internal global [10 x [30 x i8]] zeroinitializer
@fmt.n = internal unnamed_addr global i32 0
@.str = [3 x i8] c"%g\00"
@.str.1 = [3 x i8] c"-0\00"
@.str.2 = [8 x i8] c"negzero\00"
define i8* @fmt(double %0) {
%2 = load i32, i32* @fmt.n
%3 = add nsw i32 %2, 1
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* @fmt.buf, i64 0, i64 %4, i64 0
%6 = icmp eq i32 %3, 10
%7 = select i1 %6, i32 0, i32 %3
store i32 %7, i32* @fmt.n
%8 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %0)
%9 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret i8* %5
}