#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 instr(char *, char *, int);
int /*<<< orphan*/ isdigit(char);
int strlen(char *);
int /*<<< orphan*/ timlib_strlen(char *);
char *place_commas_in_number_string(char *s) {
  static char return_string[64];
  char *r_ptr;
  char *s_ptr;
  int c = 0;
  if (!timlib_strlen(s))
    return "";
  r_ptr = &return_string[63];
  *r_ptr-- = '\0';
  s_ptr = s + strlen(s) - 1;
  if (*s_ptr != '.' && !isdigit(*s_ptr))
    return s;
  if (instr(".", s, 1) != -1) {
    while (s_ptr >= s) {
      if (*s_ptr == '.') {
        *r_ptr-- = *s_ptr--;
        break;
      } else {
        *r_ptr-- = *s_ptr--;
      }
    }
  }
  while (s_ptr >= s) {
    *r_ptr-- = *s_ptr--;
    if (*s_ptr == '-') {
      *r_ptr-- = *s_ptr--;
      continue;
    }
    if (++c == 3) {
      if (s_ptr != s - 1)
        *r_ptr-- = ',';
      c = 0;
    }
  }
  return r_ptr + 1;
}


x86 assembly (clang, -O0):
<place_commas_in_number_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <timlib_strlen@plt>
cmp    $0x0,%eax
jne    1175 <place_commas_in_number_string+0x35>
lea    0xe95(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    133e <place_commas_in_number_string+0x1fe>
lea    0x2ed4(%rip),%rax
add    $0x3f,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11ed <place_commas_in_number_string+0xad>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11ed <place_commas_in_number_string+0xad>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    133e <place_commas_in_number_string+0x1fe>
mov    -0x10(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x1,%edx
call   1060 <instr@plt>
cmp    $0xffffffff,%eax
je     1281 <place_commas_in_number_string+0x141>
jmp    1210 <place_commas_in_number_string+0xd0>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     127c <place_commas_in_number_string+0x13c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1255 <place_commas_in_number_string+0x115>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    127c <place_commas_in_number_string+0x13c>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1210 <place_commas_in_number_string+0xd0>
jmp    1281 <place_commas_in_number_string+0x141>
jmp    1286 <place_commas_in_number_string+0x146>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1332 <place_commas_in_number_string+0x1f2>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12ed <place_commas_in_number_string+0x1ad>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1286 <place_commas_in_number_string+0x146>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x3,%eax
jne    132d <place_commas_in_number_string+0x1ed>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
je     1326 <place_commas_in_number_string+0x1e6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2c,(%rax)
movl   $0x0,-0x24(%rbp)
jmp    1286 <place_commas_in_number_string+0x146>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<place_commas_in_number_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <timlib_strlen@plt>
test   %eax,%eax
je     11e0 <place_commas_in_number_string+0xa0>
movb   $0x0,0x2f34(%rip)
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
mov    -0x1(%r14,%rbx,1),%al
cmp    $0x2e,%al
je     117f <place_commas_in_number_string+0x3f>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1276 <place_commas_in_number_string+0x136>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <instr@plt>
lea    0x2eed(%rip),%rcx
cmp    $0xffffffff,%eax
je     11f7 <place_commas_in_number_string+0xb7>
cmp    %r14,%rbx
jb     11f7 <place_commas_in_number_string+0xb7>
lea    0x2edb(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
mov    %rdx,%rcx
movzbl (%rbx),%edx
cmp    $0x2e,%dl
je     11ec <place_commas_in_number_string+0xac>
lea    -0x1(%rax),%rbx
mov    %dl,0x1(%rcx)
lea    -0x1(%rcx),%rdx
cmp    %r14,%rbx
jae    11c0 <place_commas_in_number_string+0x80>
jmp    11f0 <place_commas_in_number_string+0xb0>
lea    0xe1a(%rip),%r14
jmp    1276 <place_commas_in_number_string+0x136>
movb   $0x2e,0x1(%rcx)
add    $0xffffffffffffffff,%rax
mov    %rax,%rbx
cmp    %r14,%rbx
jb     126c <place_commas_in_number_string+0x12c>
xor    %edi,%edi
xor    %edx,%edx
movzbl (%rbx,%rdx,1),%eax
mov    %al,(%rcx,%rdx,1)
cmpb   $0x2d,-0x1(%rbx,%rdx,1)
jne    1230 <place_commas_in_number_string+0xf0>
movb   $0x2d,-0x1(%rcx,%rdx,1)
lea    (%rbx,%rdx,1),%rax
add    $0xfffffffffffffffe,%rax
add    $0xfffffffffffffffe,%rdx
cmp    %r14,%rax
jae    1200 <place_commas_in_number_string+0xc0>
jmp    1269 <place_commas_in_number_string+0x129>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%edi
lea    (%rcx,%rdx,1),%rsi
add    $0xffffffffffffffff,%rsi
cmp    $0x3,%edi
jne    1258 <place_commas_in_number_string+0x118>
lea    (%rbx,%rdx,1),%rax
xor    %edi,%edi
cmp    %r14,%rax
je     1258 <place_commas_in_number_string+0x118>
lea    (%rcx,%rdx,1),%rsi
add    $0xfffffffffffffffe,%rsi
movb   $0x2c,-0x1(%rcx,%rdx,1)
add    %rdx,%rbx
add    $0xffffffffffffffff,%rbx
mov    %rsi,%rcx
cmp    %r14,%rbx
jae    11fe <place_commas_in_number_string+0xbe>
jmp    126f <place_commas_in_number_string+0x12f>
add    %rdx,%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@place_commas_in_number_string.return_string = internal global [64 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
define i8* @place_commas_in_number_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i32 @timlib_strlen(i8* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %97
11: ; preds = %1
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @place_commas_in_number_string.return_string, i64 0, i64 63), i8** %4
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 -1
store i8* %13, i8** %4
store i8 0, i8* %12
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 46
br i1 %23, label %24, label %31
24: ; preds = %11
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = call i32 @isdigit(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = load i8*, i8** %3
store i8* %30, i8** %2
br label %97
31: ; preds = %24, %11
%32 = load i8*, i8** %3
%33 = call i32 @instr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 1)
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %59
35: ; preds = %31
br label %36
36: ; preds = %57, %35
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = icmp uge i8* %37, %38
br i1 %39, label %40, label %58
40: ; preds = %36
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 46
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %5
%48 = load i8, i8* %46
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i32 -1
store i8* %50, i8** %4
store i8 %48, i8* %49
br label %58
51: ; preds = %40
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i32 -1
store i8* %53, i8** %5
%54 = load i8, i8* %52
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 -1
store i8* %56, i8** %4
store i8 %54, i8* %55
br label %57
57: ; preds = %51
br label %36
58: ; preds = %45, %36
br label %59
59: ; preds = %58, %31
br label %60
60: ; preds = %93, %74, %59
%61 = load i8*, i8** %5
%62 = load i8*, i8** %3
%63 = icmp uge i8* %61, %62
br i1 %63, label %64, label %94
64: ; preds = %60
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i32 -1
store i8* %66, i8** %5
%67 = load i8, i8* %65
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i32 -1
store i8* %69, i8** %4
store i8 %67, i8* %68
%70 = load i8*, i8** %5
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 45
br i1 %73, label %74, label %80
74: ; preds = %64
%75 = load i8*, i8** %5
%76 = getelementptr inbounds i8, i8* %75, i32 -1
store i8* %76, i8** %5
%77 = load i8, i8* %75
%78 = load i8*, i8** %4
%79 = getelementptr inbounds i8, i8* %78, i32 -1
store i8* %79, i8** %4
store i8 %77, i8* %78
br label %60
80: ; preds = %64
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %6
%83 = icmp eq i32 %82, 3
br i1 %83, label %84, label %93
84: ; preds = %80
%85 = load i8*, i8** %5
%86 = load i8*, i8** %3
%87 = getelementptr inbounds i8, i8* %86, i64 -1
%88 = icmp ne i8* %85, %87
br i1 %88, label %89, label %92
89: ; preds = %84
%90 = load i8*, i8** %4
%91 = getelementptr inbounds i8, i8* %90, i32 -1
store i8* %91, i8** %4
store i8 44, i8* %90
br label %92
92: ; preds = %89, %84
store i32 0, i32* %6
br label %93
93: ; preds = %92, %80
br label %60
94: ; preds = %60
%95 = load i8*, i8** %4
%96 = getelementptr inbounds i8, i8* %95, i64 1
store i8* %96, i8** %2
br label %97
97: ; preds = %94, %29, %10
%98 = load i8*, i8** %2
ret i8* %98
}

LLVM IR (-O2):
@place_commas_in_number_string.return_string = internal global [64 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
define i8* @place_commas_in_number_string(i8* %0) {
%2 = tail call i32 @timlib_strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %64, label %4
4: ; preds = %1
store i8 0, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @place_commas_in_number_string.return_string, i64 0, i64 63)
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 46
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = tail call i32 @isdigit(i8 signext %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %64, label %14
14: ; preds = %11, %4
%15 = tail call i32 @instr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 1)
%16 = icmp eq i32 %15, -1
%17 = icmp ult i8* %8, %0
%18 = or i1 %16, %17
br i1 %18, label %29, label %19
19: ; preds = %14, %27
%20 = phi i8* [ %24, %27 ], [ %8, %14 ]
%21 = phi i8* [ %25, %27 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @place_commas_in_number_string.return_string, i64 0, i64 62), %14 ]
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 46
%24 = getelementptr inbounds i8, i8* %20, i64 -1
%25 = getelementptr inbounds i8, i8* %21, i64 -1
br i1 %23, label %26, label %27
26: ; preds = %19
store i8 46, i8* %21
br label %29
27: ; preds = %19
store i8 %22, i8* %21
%28 = icmp ult i8* %24, %0
br i1 %28, label %29, label %19
29: ; preds = %27, %26, %14
%30 = phi i8* [ %25, %26 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @place_commas_in_number_string.return_string, i64 0, i64 62), %14 ], [ %25, %27 ]
%31 = phi i8* [ %24, %26 ], [ %8, %14 ], [ %24, %27 ]
%32 = icmp ult i8* %31, %0
br i1 %32, label %61, label %33
33: ; preds = %29, %57
%34 = phi i32 [ %59, %57 ], [ 0, %29 ]
%35 = phi i8* [ %50, %57 ], [ %31, %29 ]
%36 = phi i8* [ %58, %57 ], [ %30, %29 ]
br label %37
37: ; preds = %33, %45
%38 = phi i8* [ %35, %33 ], [ %46, %45 ]
%39 = phi i8* [ %36, %33 ], [ %47, %45 ]
%40 = getelementptr inbounds i8, i8* %38, i64 -1
%41 = load i8, i8* %38
%42 = getelementptr inbounds i8, i8* %39, i64 -1
store i8 %41, i8* %39
%43 = load i8, i8* %40
%44 = icmp eq i8 %43, 45
br i1 %44, label %45, label %49
45: ; preds = %37
%46 = getelementptr inbounds i8, i8* %38, i64 -2
%47 = getelementptr inbounds i8, i8* %39, i64 -2
store i8 45, i8* %42
%48 = icmp ult i8* %46, %0
br i1 %48, label %61, label %37
49: ; preds = %37
%50 = getelementptr inbounds i8, i8* %38, i64 -1
%51 = add nsw i32 %34, 1
%52 = icmp eq i32 %51, 3
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = icmp eq i8* %38, %0
br i1 %54, label %57, label %55
55: ; preds = %53
%56 = getelementptr inbounds i8, i8* %39, i64 -2
store i8 44, i8* %42
br label %57
57: ; preds = %53, %55, %49
%58 = phi i8* [ %42, %49 ], [ %56, %55 ], [ %42, %53 ]
%59 = phi i32 [ %51, %49 ], [ 0, %55 ], [ 0, %53 ]
%60 = icmp ult i8* %50, %0
br i1 %60, label %61, label %33
61: ; preds = %57, %45, %29
%62 = phi i8* [ %30, %29 ], [ %47, %45 ], [ %58, %57 ]
%63 = getelementptr inbounds i8, i8* %62, i64 1
br label %64
64: ; preds = %11, %1, %61
%65 = phi i8* [ %63, %61 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ %0, %11 ]
ret i8* %65
}