#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 */
char *calloc(int, size_t);
int /*<<< orphan*/ cgc_memcpy(char *, char *, size_t);
size_t cgc_strlen(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *strchr(char *, char);
int sanitize_formula(char *formula, size_t size) {
  size_t i, j, len;
  len = cgc_strlen(formula);
  if (len > size)
    return -1;
  char *sanitized = calloc(1, size);
  if (sanitized == NULL)
    return -1;
  for (i = 0, j = 0; i < len; i++) {
    if (strchr("\r\n\t ", formula[i]) == NULL)
      sanitized[j++] = formula[i];
  }
  cgc_memcpy(formula, sanitized, size);
  free(sanitized);
  return 0;
}


x86 assembly (clang, -O0):
<sanitize_formula>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <cgc_strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1187 <sanitize_formula+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1248 <sanitize_formula+0xf8>
mov    -0x18(%rbp),%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b0 <sanitize_formula+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1248 <sanitize_formula+0xf8>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1227 <sanitize_formula+0xd7>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
lea    0xe23(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1211 <sanitize_formula+0xc1>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1216 <sanitize_formula+0xc6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c0 <sanitize_formula+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <cgc_memcpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_formula>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1050 <cgc_strlen@plt>
mov    $0xffffffff,%r14d
cmp    %rbp,%rax
ja     11e2 <sanitize_formula+0x92>
mov    %rax,%r15
mov    $0x1,%edi
mov    %rbp,%rsi
call   1060 <calloc@plt>
test   %rax,%rax
je     11e2 <sanitize_formula+0x92>
mov    %rax,%r12
mov    %rbp,(%rsp)
test   %r15,%r15
je     11c8 <sanitize_formula+0x78>
xor    %ebp,%ebp
lea    0xe65(%rip),%r13
xor    %r14d,%r14d
jmp    11a9 <sanitize_formula+0x59>
add    $0x1,%rbp
cmp    %rbp,%r15
je     11c8 <sanitize_formula+0x78>
movsbl (%rbx,%rbp,1),%esi
mov    %r13,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11a0 <sanitize_formula+0x50>
movzbl (%rbx,%rbp,1),%eax
mov    %al,(%r12,%r14,1)
add    $0x1,%r14
jmp    11a0 <sanitize_formula+0x50>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    (%rsp),%rdx
call   1070 <cgc_memcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\09 \00"
define i32 @sanitize_formula(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%10 = load i8*, i8** %4
%11 = call i64 @cgc_strlen(i8* %10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = load i64, i64* %5
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %54
16: ; preds = %2
%17 = load i64, i64* %5
%18 = call i8* @calloc(i32 1, i64 %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %3
br label %54
22: ; preds = %16
store i64 0, i64* %6
store i64 0, i64* %7
br label %23
23: ; preds = %44, %22
%24 = load i64, i64* %6
%25 = load i64, i64* %8
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i64, i64* %6
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %43
34: ; preds = %27
%35 = load i8*, i8** %4
%36 = load i64, i64* %6
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %9
%40 = load i64, i64* %7
%41 = add i64 %40, 1
store i64 %41, i64* %7
%42 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 %38, i8* %42
br label %43
43: ; preds = %34, %27
br label %44
44: ; preds = %43
%45 = load i64, i64* %6
%46 = add i64 %45, 1
store i64 %46, i64* %6
br label %23
47: ; preds = %23
%48 = load i8*, i8** %4
%49 = load i8*, i8** %9
%50 = load i64, i64* %5
%51 = call i32 @cgc_memcpy(i8* %48, i8* %49, i64 %50)
%52 = load i8*, i8** %9
%53 = call i32 @free(i8* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %47, %21, %15
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\09 \00"
define i32 @sanitize_formula(i8* %0, i64 %1) {
%3 = tail call i64 @cgc_strlen(i8* %0)
%4 = icmp ugt i64 %3, %1
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = tail call i8* @calloc(i32 1, i64 %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %28, label %8
8: ; preds = %5
%9 = icmp eq i64 %3, 0
br i1 %9, label %25, label %10
10: ; preds = %8, %21
%11 = phi i64 [ %23, %21 ], [ 0, %8 ]
%12 = phi i64 [ %22, %21 ], [ 0, %8 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = load i8, i8* %13
%15 = tail call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i8, i8* %13
%19 = add i64 %12, 1
%20 = getelementptr inbounds i8, i8* %6, i64 %12
store i8 %18, i8* %20
br label %21
21: ; preds = %10, %17
%22 = phi i64 [ %19, %17 ], [ %12, %10 ]
%23 = add nuw i64 %11, 1
%24 = icmp eq i64 %23, %3
br i1 %24, label %25, label %10
25: ; preds = %21, %8
%26 = tail call i32 @cgc_memcpy(i8* %0, i8* %6, i64 %1)
%27 = tail call i32 @free(i8* %6)
br label %28
28: ; preds = %25, %5, %2
%29 = phi i32 [ -1, %2 ], [ 0, %25 ], [ -1, %5 ]
ret i32 %29
}