#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *filt_comma(char *string) {
  char cur_char = 0;
  int idx = 0;
  int i = 0;
  char *buffer = 0;
  int len = 0;
  len = strlen(string) * sizeof(char) + 1;
  buffer = (char *)malloc(len);
  memset(buffer, 0, len);
  strncpy(buffer, string, len);
  buffer[len - 1] = 0;
  while (1) {
    cur_char = string[idx++];
    if (',' != cur_char) {
      buffer[i++] = cur_char;
    }
    if (idx > strlen(string)) {
      break;
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<filt_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
mov    $0x2c,%eax
cmp    %ecx,%eax
je     11ff <filt_comma+0xbf>
mov    -0x9(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    1220 <filt_comma+0xe0>
jmp    1225 <filt_comma+0xe5>
jmp    11be <filt_comma+0x7e>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filt_comma>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%r12d
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
mov    $0xffffffffffffffff,%rbp
jmp    11b3 <filt_comma+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jge    11c9 <filt_comma+0x89>
movzbl 0x1(%rbx,%rbp,1),%eax
cmp    $0x2c,%al
je     11a0 <filt_comma+0x60>
movslq %r13d,%rcx
add    $0x1,%r13d
mov    %al,(%r14,%rcx,1)
jmp    11a0 <filt_comma+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @filt_comma(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
store i8 0, i8* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i8* null, i8** %6
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%12 = add i64 %11, 1
%13 = trunc i64 %12 to i32
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = load i8*, i8** %6
%21 = load i8*, i8** %2
%22 = load i32, i32* %7
%23 = call i32 @strncpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %1, %52
%30 = load i8*, i8** %2
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %3
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = icmp ne i32 44, %37
br i1 %38, label %39, label %46
39: ; preds = %29
%40 = load i8, i8* %3
%41 = load i8*, i8** %6
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %39, %29
%47 = load i32, i32* %4
%48 = load i8*, i8** %2
%49 = call i32 @strlen(i8* %48)
%50 = icmp sgt i32 %47, %49
br i1 %50, label %51, label %52
51: ; preds = %46
br label %53
52: ; preds = %46
br label %29
53: ; preds = %51
%54 = load i8*, i8** %6
ret i8* %54
}

LLVM IR (-O2):
define i8* @filt_comma(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memset(i8* %5, i32 0, i32 %3)
%7 = tail call i32 @strncpy(i8* %5, i8* %0, i32 %3)
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 0, i8* %9
br label %10
10: ; preds = %21, %1
%11 = phi i64 [ %13, %21 ], [ 0, %1 ]
%12 = phi i32 [ %22, %21 ], [ 0, %1 ]
%13 = add nuw nsw i64 %11, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %11
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 44
br i1 %16, label %21, label %17
17: ; preds = %10
%18 = add nsw i32 %12, 1
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i8, i8* %5, i64 %19
store i8 %15, i8* %20
br label %21
21: ; preds = %17, %10
%22 = phi i32 [ %18, %17 ], [ %12, %10 ]
%23 = tail call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %11, %24
br i1 %25, label %10, label %26
26: ; preds = %21
ret i8* %5
}