#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*/ str;
typedef int /*<<< orphan*/ money;
typedef int int64_t;

/* Variables and functions */
int INT_MAX;
int INT_MIN;
int /*<<< orphan*/ abs(int /*<<< orphan*/);
scalar_t__ isdigit(char const);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ *strchr(char const *, char);
const char *form_field_getstr_money(const char *raw, void *arg) {
  static char str[(11 + 2) + 1];
  int neg = 1;
  int64_t val = 0;
  int money;
  if (strchr(raw, '-') != NULL)
    neg = -1;
  while (*raw) {
    if (!isdigit(*raw) && *raw != '$' && *raw != '.' && *raw != '-')
      break;
    if (isdigit(*raw)) {
      val *= 10;
      val += (*raw - '0');
    }
    *raw++;
  }
  money = (((val * neg) < INT_MIN)
               ? INT_MIN
               : (((val * neg) > INT_MAX) ? INT_MAX : (val * neg)));
  if (money == 0)
    str[0] = '\0';
  else if (money >= INT_MAX || money <= INT_MIN)
    snprintf(str, sizeof(str), "$%s########.##", money < 0 ? "-" : "");
  else
    snprintf(str, sizeof(str), "$%s%0d.%02d",
             (((money) < 0 && (money) > -100) ? "-" : ""), ((money) / 100),
             (abs((money) - (((money) / 100) * 100))));
  return str;
}


x86 assembly (clang, -O0):
<form_field_getstr_money>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     117d <form_field_getstr_money+0x3d>
movl   $0xffffffff,-0x14(%rbp)
jmp    1182 <form_field_getstr_money+0x42>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1218 <form_field_getstr_money+0xd8>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11da <form_field_getstr_money+0x9a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
je     11da <form_field_getstr_money+0x9a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11da <form_field_getstr_money+0x9a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11da <form_field_getstr_money+0x9a>
jmp    1218 <form_field_getstr_money+0xd8>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1207 <form_field_getstr_money+0xc7>
imul   $0xa,-0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1182 <form_field_getstr_money+0x42>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%eax
jge    123f <form_field_getstr_money+0xff>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1276 <form_field_getstr_money+0x136>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%eax
jle    1266 <form_field_getstr_money+0x126>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1270 <form_field_getstr_money+0x130>
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1292 <form_field_getstr_money+0x152>
movb   $0x0,0x2db7(%rip)
jmp    1372 <form_field_getstr_money+0x232>
mov    -0x1c(%rbp),%eax
mov    0x2d4c(%rip),%rcx
cmp    (%rcx),%eax
jge    12b6 <form_field_getstr_money+0x176>
mov    -0x1c(%rbp),%eax
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%eax
jg     12ed <form_field_getstr_money+0x1ad>
mov    -0x1c(%rbp),%edx
lea    0xd4e(%rip),%rcx
lea    0xd48(%rip),%rax
cmp    $0x0,%edx
cmovl  %rax,%rcx
lea    0x2d6f(%rip),%rdi
mov    $0xe,%esi
lea    0xd1f(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    136d <form_field_getstr_money+0x22d>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jge    1306 <form_field_getstr_money+0x1c6>
cmpl   $0xffffff9c,-0x1c(%rbp)
setg   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%dl
lea    0xcfe(%rip),%rax
lea    0xcf8(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   1040 <abs@plt>
mov    -0x38(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    %eax,%r9d
lea    0x2cea(%rip),%rdi
mov    $0xe,%esi
lea    0xcab(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1372 <form_field_getstr_money+0x232>
lea    0x2ccb(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<form_field_getstr_money>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2d,%esi
call   1040 <strchr@plt>
mov    %rax,%r14
mov    (%rbx),%al
xor    %r15d,%r15d
test   %al,%al
je     11a8 <form_field_getstr_money+0x78>
movabs $0x601000000000,%r12
jmp    116c <form_field_getstr_money+0x3c>
nopl   (%rax)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11a8 <form_field_getstr_money+0x78>
movsbl %al,%edi
call   1030 <isdigit@plt>
movzbl (%rbx),%ecx
test   %rax,%rax
jne    118a <form_field_getstr_money+0x5a>
cmp    $0x2e,%cl
ja     11a8 <form_field_getstr_money+0x78>
movzbl %cl,%eax
bt     %rax,%r12
jae    11a8 <form_field_getstr_money+0x78>
movsbl %cl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1160 <form_field_getstr_money+0x30>
lea    (%r15,%r15,4),%eax
movsbl (%rbx),%ecx
lea    (%rcx,%rax,2),%r15d
add    $0xffffffd0,%r15d
jmp    1160 <form_field_getstr_money+0x30>
mov    %r15d,%esi
neg    %esi
test   %r14,%r14
cmove  %r15d,%esi
mov    0x2e25(%rip),%rax
mov    (%rax),%ecx
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
cmp    %edx,%esi
mov    %esi,%eax
cmovg  %edx,%eax
cmp    %ecx,%esi
cmovl  %ecx,%eax
test   %eax,%eax
je     1237 <form_field_getstr_money+0x107>
cmp    %edx,%eax
jge    1240 <form_field_getstr_money+0x110>
cmp    %ecx,%eax
jle    1240 <form_field_getstr_money+0x110>
cmp    $0xffffff9d,%eax
lea    0xe27(%rip),%rdx
lea    0xe1f(%rip),%rcx
cmovae %rdx,%rcx
movslq %eax,%rdx
imul   $0x51eb851f,%rdx,%r8
mov    %r8,%rdx
shr    $0x3f,%rdx
sar    $0x25,%r8
add    %edx,%r8d
imul   $0xffffff9c,%r8d,%edx
add    %eax,%edx
mov    %edx,%r9d
neg    %r9d
cmovs  %edx,%r9d
lea    0x2e1a(%rip),%rdi
lea    0xde8(%rip),%rdx
mov    $0xe,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    126e <form_field_getstr_money+0x13e>
movb   $0x0,0x2dfe(%rip)
jmp    126e <form_field_getstr_money+0x13e>
test   %eax,%eax
lea    0xdc6(%rip),%rax
lea    0xdbe(%rip),%rcx
cmovs  %rax,%rcx
lea    0x2de1(%rip),%rdi
lea    0xd9e(%rip),%rdx
mov    $0xe,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x2dc7(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@form_field_getstr_money.str = internal global [14 x i8] zeroinitializer
@INT_MIN = global i32 0
@INT_MAX = global i32 0
@.str = [15 x i8] c"$%s########.##\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"$%s%0d.%02d\00"
define i8* @form_field_getstr_money(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %5
store i32 0, i32* %6
%8 = load i8*, i8** %3
%9 = call i32* @strchr(i8* %8, i8 signext 45)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %5
br label %12
12: ; preds = %11, %2
br label %13
13: ; preds = %52, %12
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %56
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 36
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 46
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 45
br i1 %36, label %37, label %38
37: ; preds = %32
br label %56
38: ; preds = %32, %27, %22, %17
%39 = load i8*, i8** %3
%40 = load i8, i8* %39
%41 = call i64 @isdigit(i8 signext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %38
%44 = load i32, i32* %6
%45 = mul nsw i32 %44, 10
store i32 %45, i32* %6
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, %49
store i32 %51, i32* %6
br label %52
52: ; preds = %43, %38
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %3
%55 = load i8, i8* %53
br label %13
56: ; preds = %37, %13
%57 = load i32, i32* %6
%58 = load i32, i32* %5
%59 = mul nsw i32 %57, %58
%60 = load i32, i32* @INT_MIN
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = load i32, i32* @INT_MIN
br label %78
64: ; preds = %56
%65 = load i32, i32* %6
%66 = load i32, i32* %5
%67 = mul nsw i32 %65, %66
%68 = load i32, i32* @INT_MAX
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = load i32, i32* @INT_MAX
br label %76
72: ; preds = %64
%73 = load i32, i32* %6
%74 = load i32, i32* %5
%75 = mul nsw i32 %73, %74
br label %76
76: ; preds = %72, %70
%77 = phi i32 [ %71, %70 ], [ %75, %72 ]
br label %78
78: ; preds = %76, %62
%79 = phi i32 [ %63, %62 ], [ %77, %76 ]
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78
store i8 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0)
br label %117
83: ; preds = %78
%84 = load i32, i32* %7
%85 = load i32, i32* @INT_MAX
%86 = icmp sge i32 %84, %85
br i1 %86, label %91, label %87
87: ; preds = %83
%88 = load i32, i32* %7
%89 = load i32, i32* @INT_MIN
%90 = icmp sle i32 %88, %89
br i1 %90, label %91, label %97
91: ; preds = %87, %83
%92 = load i32, i32* %7
%93 = icmp slt i32 %92, 0
%94 = zext i1 %93 to i64
%95 = select i1 %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%96 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %95)
br label %116
97: ; preds = %87
%98 = load i32, i32* %7
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = load i32, i32* %7
%102 = icmp sgt i32 %101, -100
br label %103
103: ; preds = %100, %97
%104 = phi i1 [ false, %97 ], [ %102, %100 ]
%105 = zext i1 %104 to i64
%106 = select i1 %104, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%107 = load i32, i32* %7
%108 = sdiv i32 %107, 100
%109 = load i32, i32* %7
%110 = load i32, i32* %7
%111 = sdiv i32 %110, 100
%112 = mul nsw i32 %111, 100
%113 = sub nsw i32 %109, %112
%114 = call i32 @abs(i32 %113)
%115 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %106, i32 %108, i32 %114)
br label %116
116: ; preds = %103, %91
br label %117
117: ; preds = %116, %82
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0)
}

LLVM IR (-O2):
@form_field_getstr_money.str = internal global [14 x i8] zeroinitializer
@INT_MIN = global i32 0
@INT_MAX = global i32 0
@.str = [15 x i8] c"$%s########.##\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"$%s%0d.%02d\00"
define i8* @form_field_getstr_money(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i32* @strchr(i8* %0, i8 signext 45)
%4 = icmp eq i32* %3, null
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %2, %24
%8 = phi i8 [ %27, %24 ], [ %5, %2 ]
%9 = phi i8* [ %26, %24 ], [ %0, %2 ]
%10 = phi i32 [ %25, %24 ], [ 0, %2 ]
%11 = tail call i64 @isdigit(i8 signext %8)
%12 = icmp eq i64 %11, 0
%13 = load i8, i8* %9
br i1 %12, label %14, label %15
14: ; preds = %7
switch i8 %13, label %29 [
i8 36, label %15
i8 46, label %15
i8 45, label %15
]
15: ; preds = %7, %14, %14, %14
%16 = tail call i64 @isdigit(i8 signext %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = mul nsw i32 %10, 10
%20 = load i8, i8* %9
%21 = sext i8 %20 to i32
%22 = add i32 %19, -48
%23 = add i32 %22, %21
br label %24
24: ; preds = %18, %15
%25 = phi i32 [ %23, %18 ], [ %10, %15 ]
%26 = getelementptr inbounds i8, i8* %9, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %7
29: ; preds = %24, %14, %2
%30 = phi i32 [ 0, %2 ], [ %10, %14 ], [ %25, %24 ]
%31 = sub nsw i32 0, %30
%32 = select i1 %4, i32 %30, i32 %31
%33 = load i32, i32* @INT_MIN
%34 = icmp slt i32 %32, %33
%35 = load i32, i32* @INT_MAX
%36 = icmp sgt i32 %32, %35
%37 = select i1 %36, i32 %35, i32 %32
%38 = select i1 %34, i32 %33, i32 %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %29
store i8 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0)
br label %57
41: ; preds = %29
%42 = icmp slt i32 %38, %35
%43 = icmp sgt i32 %38, %33
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = icmp slt i32 %38, 0
%47 = select i1 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%48 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %47)
br label %57
49: ; preds = %41
%50 = icmp ugt i32 %38, -100
%51 = select i1 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%52 = sdiv i32 %38, 100
%53 = mul nsw i32 %52, -100
%54 = add i32 %53, %38
%55 = tail call i32 @llvm.abs.i32(i32 %54, i1 true)
%56 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %51, i32 %52, i32 %55)
br label %57
57: ; preds = %45, %49, %40
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @form_field_getstr_money.str, i64 0, i64 0)
}