#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 /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, size_t);
size_t text_normalize_buf(unsigned char *, size_t, int, size_t *, int *);
scalar_t__ xmalloc(size_t);
unsigned char *xstrdup(char *);
size_t text_normalize_dup(const unsigned char *in_text, size_t in_size,
                          int op_mask, unsigned char **p_out_text,
                          size_t *p_count, int *p_done_mask) {
  unsigned char *out_text = 0;
  if (!in_size) {
    *p_out_text = xstrdup("");
    if (p_count)
      *p_count = 0;
    return 0;
  }
  *p_out_text = out_text = (unsigned char *)xmalloc(in_size + 2);
  memcpy(out_text, in_text, in_size + 1);
  return text_normalize_buf(out_text, in_size, op_mask, p_count, p_done_mask);
}


x86 assembly (clang, -O0):
<text_normalize_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <text_normalize_dup+0x6b>
lea    0xe87(%rip),%rdi
call   1040 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     119e <text_normalize_dup+0x5e>
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f7 <text_normalize_dup+0xb7>
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1030 <xmalloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1060 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1050 <text_normalize_buf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_normalize_dup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%rbp
test   %rsi,%rsi
je     11a5 <text_normalize_dup+0x65>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0x2(%rsi),%rdi
mov    %r9,(%rsp)
call   1030 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,0x0(%rbp)
lea    0x1(%rbx),%rdx
mov    %rax,%rdi
mov    %r13,%rsi
call   1060 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
mov    (%rsp),%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <text_normalize_buf@plt>
lea    0xe54(%rip),%rdi
call   1040 <xstrdup@plt>
mov    %rax,0x0(%rbp)
test   %r12,%r12
je     11c2 <text_normalize_dup+0x82>
movq   $0x0,(%r12)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i64 @text_normalize_dup(i8* %0, i64 %1, i32 %2, i8** %3, i64* %4, i32* %5) {
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i64*
%13 = alloca i32*
%14 = alloca i8*
store i8* %0, i8** %8
store i64 %1, i64* %9
store i32 %2, i32* %10
store i8** %3, i8*** %11
store i64* %4, i64** %12
store i32* %5, i32** %13
store i8* null, i8** %14
%15 = load i64, i64* %9
%16 = icmp ne i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %6
%18 = call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%19 = load i8**, i8*** %11
store i8* %18, i8** %19
%20 = load i64*, i64** %12
%21 = icmp ne i64* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i64*, i64** %12
store i64 0, i64* %23
br label %24
24: ; preds = %22, %17
store i64 0, i64* %7
br label %42
25: ; preds = %6
%26 = load i64, i64* %9
%27 = add i64 %26, 2
%28 = call i64 @xmalloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %14
%30 = load i8**, i8*** %11
store i8* %29, i8** %30
%31 = load i8*, i8** %14
%32 = load i8*, i8** %8
%33 = load i64, i64* %9
%34 = add i64 %33, 1
%35 = call i32 @memcpy(i8* %31, i8* %32, i64 %34)
%36 = load i8*, i8** %14
%37 = load i64, i64* %9
%38 = load i32, i32* %10
%39 = load i64*, i64** %12
%40 = load i32*, i32** %13
%41 = call i64 @text_normalize_buf(i8* %36, i64 %37, i32 %38, i64* %39, i32* %40)
store i64 %41, i64* %7
br label %42
42: ; preds = %25, %24
%43 = load i64, i64* %7
ret i64 %43
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i64 @text_normalize_dup(i8* %0, i64 %1, i32 %2, i8** nocapture writeonly %3, i64* %4, i32* %5) {
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = tail call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %3
%10 = icmp eq i64* %4, null
br i1 %10, label %19, label %11
11: ; preds = %8
store i64 0, i64* %4
br label %19
12: ; preds = %6
%13 = add i64 %1, 2
%14 = tail call i64 @xmalloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = add i64 %1, 1
%17 = tail call i32 @memcpy(i8* %15, i8* %0, i64 %16)
%18 = tail call i64 @text_normalize_buf(i8* %15, i64 %1, i32 %2, i64* %4, i32* %5)
br label %19
19: ; preds = %8, %11, %12
%20 = phi i64 [ %18, %12 ], [ 0, %11 ], [ 0, %8 ]
ret i64 %20
}