#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned int);
int /*<<< orphan*/ text_convert(char *, size_t, char *, unsigned int);
char *text_field_convert(const char *field, unsigned int len) {
  unsigned int conv_max_len = len * 16 + 1;
  char *field_local = malloc(conv_max_len);
  if (!field_local) {
    fprintf(stderr, "Error allocating space for text conversion\n");
    return NULL;
  }
  if (*field) {
    char field_copy[len + 1];
    field_copy[len] = '\0';
    (void)strncpy(field_copy, field, len);
    size_t srclen = strlen(field_copy) + 1;
    if (!text_convert(field_copy, srclen, field_local, conv_max_len)) {
      free(field_local);
      field_local = NULL;
    }
  } else {
    *field_local = '\0';
  }
  return field_local;
}


x86 assembly (clang, -O0):
<text_field_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <text_field_convert+0x54>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1258 <text_field_convert+0xf8>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1249 <text_field_convert+0xe9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
movb   $0x0,(%rdi,%rax,1)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1080 <text_convert@plt>
cmp    $0x0,%eax
jne    123d <text_field_convert+0xdd>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    1250 <text_field_convert+0xf0>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_field_convert>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%ebx
shl    $0x4,%ebx
or     $0x1,%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11f1 <text_field_convert+0x91>
mov    %rax,%r14
cmpb   $0x0,(%r12)
je     120b <text_field_convert+0xab>
mov    %rsp,-0x30(%rbp)
lea    0x1(%r15),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r15d,%eax
movb   $0x0,(%rax,%r13,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rsi
mov    %r13,%rdi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1080 <text_convert@plt>
test   %eax,%eax
jne    11eb <text_field_convert+0x8b>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    -0x30(%rbp),%rsp
jmp    120f <text_field_convert+0xaf>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
xor    %r14d,%r14d
jmp    120f <text_field_convert+0xaf>
movb   $0x0,(%r14)
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Error allocating space for text conversion\0A\00"
define i8* @text_field_convert(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i32, i32* %5
%12 = mul i32 %11, 16
%13 = add i32 %12, 1
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %54
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %21
%26 = load i32, i32* %5
%27 = add i32 %26, 1
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %8
%30 = alloca i8, i64 %28
store i64 %28, i64* %9
%31 = load i32, i32* %5
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = call i32 @strncpy(i8* %30, i8* %34, i32 %35)
%37 = call i32 @strlen(i8* %30)
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
store i64 %39, i64* %10
%40 = load i64, i64* %10
%41 = load i8*, i8** %7
%42 = load i32, i32* %6
%43 = call i32 @text_convert(i8* %30, i64 %40, i8* %41, i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %25
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
store i8* null, i8** %7
br label %48
48: ; preds = %45, %25
%49 = load i8*, i8** %8
br label %52
50: ; preds = %21
%51 = load i8*, i8** %7
store i8 0, i8* %51
br label %52
52: ; preds = %50, %48
%53 = load i8*, i8** %7
store i8* %53, i8** %3
br label %54
54: ; preds = %52, %18
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Error allocating space for text conversion\0A\00"
define i8* @text_field_convert(i8* %0, i32 %1) {
%3 = shl i32 %1, 4
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %31
10: ; preds = %2
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 0
br i1 %12, label %30, label %13
13: ; preds = %10
%14 = add i32 %1, 1
%15 = zext i32 %14 to i64
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = zext i32 %1 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
%20 = call i32 @strncpy(i8* %17, i8* %0, i32 %1)
%21 = call i32 @strlen(i8* %17)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = call i32 @text_convert(i8* %17, i64 %23, i8* %5, i32 %4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = call i32 @free(i8* %5)
br label %28
28: ; preds = %26, %13
%29 = phi i8* [ %5, %13 ], [ null, %26 ]
br label %31
30: ; preds = %10
store i8 0, i8* %5
br label %31
31: ; preds = %28, %30, %7
%32 = phi i8* [ null, %7 ], [ %29, %28 ], [ %5, %30 ]
ret i8* %32
}