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

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ ts_LOGf(char *, char *, char *, ...);
void dvb_print_string(char *pad, char *prefix, uint8_t *input,
                      int text_length) {
  if (text_length < 0) {
    ts_LOGf("%s  !!! %s text_length < 0, %d\n", pad, prefix, text_length);
    return;
  }
  if (text_length == 0) {
    ts_LOGf("%s  %s \"\" (size: %d)\n", pad, prefix, text_length);
    return;
  }
  char *text = calloc(1, text_length + 1);
  memcpy(text, input, text_length);
  if (text[0] < 32)
    ts_LOGf("%s  %s \"%s\" (charset: 0x%02x size: %d)\n", pad, prefix, text + 1,
            text[0], text_length - 1);
  else
    ts_LOGf("%s  %s \"%s\" (size: %d)\n", pad, prefix, text, text_length);
  free(text);
}


x86 assembly (clang, -O0):
<dvb_print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117f <dvb_print_string+0x3f>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1060 <ts_LOGf@plt>
jmp    1235 <dvb_print_string+0xf5>
cmpl   $0x0,-0x1c(%rbp)
jne    11a7 <dvb_print_string+0x67>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1060 <ts_LOGf@plt>
jmp    1235 <dvb_print_string+0xf5>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    120e <dvb_print_string+0xce>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
movsbl (%rax),%r8d
mov    -0x1c(%rbp),%r9d
sub    $0x1,%r9d
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1060 <ts_LOGf@plt>
jmp    122c <dvb_print_string+0xec>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <ts_LOGf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvb_print_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
test   %ecx,%ecx
js     11a5 <dvb_print_string+0x65>
je     11b6 <dvb_print_string+0x76>
mov    %rdx,%r13
lea    0x1(%rbx),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movsbl (%r12),%r8d
cmp    $0x1f,%r8d
jg     11d5 <dvb_print_string+0x95>
mov    %r12,%rcx
add    $0x1,%rcx
add    $0xffffffff,%ebx
lea    0xea3(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%r9d
xor    %eax,%eax
call   1060 <ts_LOGf@plt>
jmp    11ef <dvb_print_string+0xaf>
lea    0xe54(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
jmp    11c5 <dvb_print_string+0x85>
lea    0xe63(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <ts_LOGf@plt>
lea    0xe82(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <ts_LOGf@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"%s !!! %s text_length < 0, %d\0A\00"
@.str.1 = [22 x i8] c"%s %s \22\22 (size: %d)\0A\00"
@.str.2 = [40 x i8] c"%s %s \22%s\22 (charset: 0x%02x size: %d)\0A\00"
@.str.3 = [24 x i8] c"%s %s \22%s\22 (size: %d)\0A\00"
define void @dvb_print_string(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = load i32, i32* %8
%16 = call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14, i32 %15)
br label %59
17: ; preds = %4
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = load i32, i32* %8
%24 = call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22, i32 %23)
br label %59
25: ; preds = %17
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = call i8* @calloc(i32 1, i32 %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = load i32*, i32** %7
%31 = load i32, i32* %8
%32 = call i32 @memcpy(i8* %29, i32* %30, i32 %31)
%33 = load i8*, i8** %9
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp slt i32 %36, 32
br i1 %37, label %38, label %50
38: ; preds = %25
%39 = load i8*, i8** %5
%40 = load i8*, i8** %6
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 1
%49 = call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %40, i8* %42, i32 %46, i32 %48)
br label %56
50: ; preds = %25
%51 = load i8*, i8** %5
%52 = load i8*, i8** %6
%53 = load i8*, i8** %9
%54 = load i32, i32* %8
%55 = call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52, i8* %53, i32 %54)
br label %56
56: ; preds = %50, %38
%57 = load i8*, i8** %9
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %20, %12
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"%s !!! %s text_length < 0, %d\0A\00"
@.str.1 = [22 x i8] c"%s %s \22\22 (size: %d)\0A\00"
@.str.2 = [40 x i8] c"%s %s \22%s\22 (charset: 0x%02x size: %d)\0A\00"
@.str.3 = [24 x i8] c"%s %s \22%s\22 (size: %d)\0A\00"
define void @dvb_print_string(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = icmp slt i32 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %3)
br label %27
8: ; preds = %4
%9 = icmp eq i32 %3, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i32 0)
br label %27
12: ; preds = %8
%13 = add nuw nsw i32 %3, 1
%14 = tail call i8* @calloc(i32 1, i32 %13)
%15 = tail call i32 @memcpy(i8* %14, i32* %2, i32 %3)
%16 = load i8, i8* %14
%17 = icmp slt i8 %16, 32
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = sext i8 %16 to i32
%20 = getelementptr inbounds i8, i8* %14, i64 1
%21 = add nsw i32 %3, -1
%22 = tail call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i8* %20, i32 %19, i32 %21)
br label %25
23: ; preds = %12
%24 = tail call i32 (i8*, i8*, i8*, ...) @ts_LOGf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i8* %14, i32 %3)
br label %25
25: ; preds = %23, %18
%26 = tail call i32 @free(i8* %14)
br label %27
27: ; preds = %25, %10, %6
ret void
}