#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 */
char *ic_string_contents_steal(struct ic_string *);
int /*<<< orphan*/ ic_string_destroy(struct ic_string *, int);
int /*<<< orphan*/ puts(char *);
char *ic_string_contents_steal_and_destroy(struct ic_string *string) {
  char *ch = 0;
  if (!string) {
    puts("ic_string_contents_steal_and_destroy: null string passed in");
    return 0;
  }
  ch = ic_string_contents_steal(string);
  if (!ch) {
    puts("ic_string_contents_steal_and_destroy: call to "
         "ic_string_contents_steal failed");
    return 0;
  }
  if (!ic_string_destroy(string, 1)) {
    puts("ic_string_contents_steal: call to ic_string_destroy failed");
    return 0;
  }
  return ch;
}


x86 assembly (clang, -O0):
<ic_string_contents_steal_and_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1168 <ic_string_contents_steal_and_destroy+0x38>
lea    0xeaa(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <ic_string_contents_steal_and_destroy+0xa1>
mov    -0x10(%rbp),%rdi
call   1030 <ic_string_contents_steal@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1199 <ic_string_contents_steal_and_destroy+0x69>
lea    0xeb5(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <ic_string_contents_steal_and_destroy+0xa1>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <ic_string_destroy@plt>
cmp    $0x0,%eax
jne    11c9 <ic_string_contents_steal_and_destroy+0x99>
lea    0xed3(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <ic_string_contents_steal_and_destroy+0xa1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_string_contents_steal_and_destroy>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1163 <ic_string_contents_steal_and_destroy+0x33>
mov    %rdi,%rbx
call   1030 <ic_string_contents_steal@plt>
test   %rax,%rax
je     116c <ic_string_contents_steal_and_destroy+0x3c>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <ic_string_destroy@plt>
test   %eax,%eax
jne    117b <ic_string_contents_steal_and_destroy+0x4b>
lea    0xf29(%rip),%rdi
jmp    1173 <ic_string_contents_steal_and_destroy+0x43>
lea    0xe96(%rip),%rdi
jmp    1173 <ic_string_contents_steal_and_destroy+0x43>
lea    0xec9(%rip),%rdi
call   1050 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ic_string = type { i32 }
@.str = [60 x i8] c"ic_string_contents_steal_and_destroy: null string passed in\00"
@.str.1 = [78 x i8] c"ic_string_contents_steal_and_destroy: call to ic_string_contents_steal failed\00"
@.str.2 = [59 x i8] c"ic_string_contents_steal: call to ic_string_destroy failed\00"
define i8* @ic_string_contents_steal_and_destroy(%struct.ic_string* %0) {
%2 = alloca i8*
%3 = alloca %struct.ic_string*
%4 = alloca i8*
store %struct.ic_string* %0, %struct.ic_string** %3
store i8* null, i8** %4
%5 = load %struct.ic_string*, %struct.ic_string** %3
%6 = icmp ne %struct.ic_string* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @puts(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %24
9: ; preds = %1
%10 = load %struct.ic_string*, %struct.ic_string** %3
%11 = call i8* @ic_string_contents_steal(%struct.ic_string* %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @puts(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %24
16: ; preds = %9
%17 = load %struct.ic_string*, %struct.ic_string** %3
%18 = call i32 @ic_string_destroy(%struct.ic_string* %17, i32 1)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %24
22: ; preds = %16
%23 = load i8*, i8** %4
store i8* %23, i8** %2
br label %24
24: ; preds = %22, %20, %14, %7
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
%struct.ic_string = type { i32 }
@.str = [60 x i8] c"ic_string_contents_steal_and_destroy: null string passed in\00"
@.str.1 = [78 x i8] c"ic_string_contents_steal_and_destroy: call to ic_string_contents_steal failed\00"
@.str.2 = [59 x i8] c"ic_string_contents_steal: call to ic_string_destroy failed\00"
define i8* @ic_string_contents_steal_and_destroy(%struct.ic_string* %0) {
%2 = icmp eq %struct.ic_string* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call i8* @ic_string_contents_steal(%struct.ic_string* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @ic_string_destroy(%struct.ic_string* %0, i32 1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6, %3, %1
%10 = phi i8* [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), %6 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
br label %12
12: ; preds = %9, %6
%13 = phi i8* [ %4, %6 ], [ null, %9 ]
ret i8* %13
}