#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*/ wchar_t;

/* Variables and functions */
scalar_t__ _crab(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
char *malloc(size_t);
int strlen(char const *);
int /*<<< orphan*/ *utf82wc(char *, size_t);
int /*<<< orphan*/ wc2utf8(int /*<<< orphan*/ *, char *, size_t);
char *_filter(const char *msg) {
  char *tmp = (char *)msg;
  size_t slen = strlen(msg) + 1;
  wchar_t *wmsg = utf82wc(tmp, slen);
  char *new_msg = 0;
  if (wmsg) {
    if (_crab(wmsg)) {
      new_msg = malloc(slen);
      wc2utf8(wmsg, new_msg, slen);
    }
    free(wmsg);
  }
  return new_msg;
}


x86 assembly (clang, -O0):
<_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <utf82wc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <_filter+0x84>
mov    -0x20(%rbp),%rdi
call   1050 <_crab@plt>
cmp    $0x0,%rax
je     11db <_filter+0x7b>
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <wc2utf8@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_filter>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1060 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <utf82wc@plt>
test   %rax,%rax
je     11ae <_filter+0x4e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <_crab@plt>
test   %rax,%rax
je     11b3 <_filter+0x53>
mov    %r14,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <wc2utf8@plt>
jmp    11b6 <_filter+0x56>
xor    %r15d,%r15d
jmp    11be <_filter+0x5e>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @_filter(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
store i64 %11, i64* %4
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i32* @utf82wc(i8* %12, i64 %13)
store i32* %14, i32** %5
store i8* null, i8** %6
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %31
17: ; preds = %1
%18 = load i32*, i32** %5
%19 = call i64 @_crab(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i64, i64* %4
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %6
%24 = load i32*, i32** %5
%25 = load i8*, i8** %6
%26 = load i64, i64* %4
%27 = call i32 @wc2utf8(i32* %24, i8* %25, i64 %26)
br label %28
28: ; preds = %21, %17
%29 = load i32*, i32** %5
%30 = call i32 @free(i32* %29)
br label %31
31: ; preds = %28, %1
%32 = load i8*, i8** %6
ret i8* %32
}

LLVM IR (-O2):
define i8* @_filter(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = sext i32 %3 to i64
%5 = tail call i32* @utf82wc(i8* %0, i64 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = tail call i64 @_crab(i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i8* @malloc(i64 %4)
%12 = tail call i32 @wc2utf8(i32* %5, i8* %11, i64 %4)
br label %13
13: ; preds = %10, %7
%14 = phi i8* [ %11, %10 ], [ null, %7 ]
%15 = tail call i32 @free(i32* %5)
br label %16
16: ; preds = %13, %1
%17 = phi i8* [ %14, %13 ], [ null, %1 ]
ret i8* %17
}