#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 */
struct ic_string {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ic_string_append_char(struct ic_string *, char *,
                                         unsigned int);
int /*<<< orphan*/ puts(char *);
unsigned int strlen(char *);
unsigned int ic_string_append_cstr(struct ic_string *to, char *from) {
  unsigned int len = 0;
  if (!to) {
    puts("ic_string_append_cstr: to was null");
    return 0;
  }
  if (!from) {
    puts("ic_string_append_cstr: from was null");
    return 0;
  }
  len = strlen(from);
  if (!len) {
    puts("ic_string_append_cstr: call to strlen failed or 0 length string "
         "given");
    return 0;
  }
  if (!ic_string_append_char(to, from, len)) {
    puts("ic_string_append_cstr: call to ic_string_append_char failed");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ic_string_append_cstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <ic_string_append_cstr+0x3a>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <ic_string_append_cstr+0xc3>
cmpq   $0x0,-0x18(%rbp)
jne    118d <ic_string_append_cstr+0x5d>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <ic_string_append_cstr+0xc3>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11bb <ic_string_append_cstr+0x8b>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <ic_string_append_cstr+0xc3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <ic_string_append_char@plt>
cmp    $0x0,%eax
jne    11ec <ic_string_append_cstr+0xbc>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <ic_string_append_cstr+0xc3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_string_append_cstr>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <ic_string_append_cstr+0x41>
mov    %rsi,%r14
test   %rsi,%rsi
je     117a <ic_string_append_cstr+0x4a>
mov    %rdi,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     1183 <ic_string_append_cstr+0x53>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <ic_string_append_char@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    1191 <ic_string_append_cstr+0x61>
lea    0xf1f(%rip),%rdi
jmp    118a <ic_string_append_cstr+0x5a>
lea    0xe88(%rip),%rdi
jmp    118a <ic_string_append_cstr+0x5a>
lea    0xea2(%rip),%rdi
jmp    118a <ic_string_append_cstr+0x5a>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ic_string = type { i32 }
@.str = [35 x i8] c"ic_string_append_cstr: to was null\00"
@.str.1 = [37 x i8] c"ic_string_append_cstr: from was null\00"
@.str.2 = [70 x i8] c"ic_string_append_cstr: call to strlen failed or 0 length string given\00"
@.str.3 = [60 x i8] c"ic_string_append_cstr: call to ic_string_append_char failed\00"
define i32 @ic_string_append_cstr(%struct.ic_string* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.ic_string*
%5 = alloca i8*
%6 = alloca i32
store %struct.ic_string* %0, %struct.ic_string** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%7 = load %struct.ic_string*, %struct.ic_string** %4
%8 = icmp ne %struct.ic_string* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %32
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %32
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @puts(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %32
23: ; preds = %16
%24 = load %struct.ic_string*, %struct.ic_string** %4
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = call i32 @ic_string_append_char(%struct.ic_string* %24, i8* %25, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = call i32 @puts(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %32
31: ; preds = %23
store i32 1, i32* %3
br label %32
32: ; preds = %31, %29, %21, %14, %9
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.ic_string = type { i32 }
@.str = [35 x i8] c"ic_string_append_cstr: to was null\00"
@.str.1 = [37 x i8] c"ic_string_append_cstr: from was null\00"
@.str.2 = [70 x i8] c"ic_string_append_cstr: call to strlen failed or 0 length string given\00"
@.str.3 = [60 x i8] c"ic_string_append_cstr: call to ic_string_append_char failed\00"
define i32 @ic_string_append_cstr(%struct.ic_string* %0, i8* %1) {
%3 = icmp eq %struct.ic_string* %0, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = icmp eq i8* %1, null
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @ic_string_append_char(%struct.ic_string* %0, i8* %1, i32 %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9, %6, %4, %2
%13 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), %9 ]
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %16
}