#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 char uint8_t;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *init_dvb_string(uint8_t encoding, char *text) {
  if (!text)
    return NULL;
  int len = strlen(text);
  if (!len)
    return NULL;
  char *dvbtext = calloc(1, len + 2);
  memcpy(dvbtext + 1, text, len);
  dvbtext[0] = encoding;
  return dvbtext;
}


x86 assembly (clang, -O0):
<init_dvb_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <init_dvb_string+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <init_dvb_string+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    117d <init_dvb_string+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <init_dvb_string+0x86>
mov    -0x1c(%rbp),%esi
add    $0x2,%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x9(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_dvb_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1178 <init_dvb_string+0x48>
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1178 <init_dvb_string+0x48>
mov    %eax,%r15d
mov    %eax,%esi
add    $0x2,%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%rbp
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
mov    %r14b,0x0(%rbp)
jmp    117a <init_dvb_string+0x4a>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @init_dvb_string(i8 signext %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = add nsw i32 %5, 2
%9 = tail call i8* @calloc(i32 1, i32 %8)
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = tail call i32 @memcpy(i8* %10, i8* %1, i32 %5)
store i8 %0, i8* %9
br label %12
12: ; preds = %7, %4, %2
%13 = phi i8* [ null, %2 ], [ %9, %7 ], [ null, %4 ]
ret i8* %13
}