#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 *, char *);
scalar_t__ strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void formatval(char *str, char *dst) {
  int n;
  char *ptr;
  n = 0;
  for (ptr = str; (n == 0 && *ptr != 0); ptr++)
    if (strchr("0123456789.", *ptr) == 0)
      n = 1;
  if (n == 0 && *str != 0)
    strcpy(dst, str);
  else
    sprintf(dst, "\"%s\"", str);
}


x86 assembly (clang, -O0):
<formatval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jne    116e <formatval+0x3e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117e <formatval+0x4e>
jmp    11b8 <formatval+0x88>
mov    -0x20(%rbp),%rax
lea    0xe77(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    11a2 <formatval+0x72>
movl   $0x1,-0x14(%rbp)
jmp    11a7 <formatval+0x77>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114f <formatval+0x1f>
cmpl   $0x0,-0x14(%rbp)
jne    11e4 <formatval+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e4 <formatval+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11f8 <formatval+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatval>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xebb(%rip),%r12
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
test   %al,%al
je     116d <formatval+0x3d>
movsbl %al,%esi
mov    %r12,%rdi
call   1040 <strchr@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <formatval+0x20>
jmp    1189 <formatval+0x59>
cmpb   $0x0,(%r15)
je     1189 <formatval+0x59>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"0123456789.\00"
@.str.1 = [5 x i8] c"\22%s\22\00"
define void @formatval(i8* %0, i8* %1) {
br label %3
3: ; preds = %2, %7
%4 = phi i8* [ %0, %2 ], [ %10, %7 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i64 @strchr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %9, label %16, label %3
11: ; preds = %3
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %18
16: ; preds = %7, %11
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %14
ret void
}