#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 */
void *cag_strdup(char *);
int /*<<< orphan*/ free(char *);
int cag_alloc_str_str(void *to, const void *from) {
  static struct str_str {
    char *key;
    char *data;
  } * x;
  const struct str_str *y;
  x = to;
  y = from;
  x->key = cag_strdup(y->key);
  if (!x->key)
    return 0;
  x->data = cag_strdup(y->data);
  if (!x->data) {
    free(x->key);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<cag_alloc_str_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2efd(%rip)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <cag_strdup@plt>
mov    %rax,%rcx
mov    0x2edf(%rip),%rax
mov    %rcx,(%rax)
mov    0x2ed5(%rip),%rax
cmpq   $0x0,(%rax)
jne    1179 <cag_alloc_str_str+0x59>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <cag_alloc_str_str+0xa8>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <cag_strdup@plt>
mov    %rax,%rcx
mov    0x2ea8(%rip),%rax
mov    %rcx,0x8(%rax)
mov    0x2e9d(%rip),%rax
cmpq   $0x0,0x8(%rax)
jne    11c1 <cag_alloc_str_str+0xa1>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <cag_alloc_str_str+0xa8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cag_alloc_str_str>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,0x2f0d(%rip)
mov    (%rsi),%rdi
call   1040 <cag_strdup@plt>
mov    %rax,%rcx
mov    0x2efb(%rip),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
test   %rcx,%rcx
je     1168 <cag_alloc_str_str+0x48>
mov    0x8(%rbx),%rdi
call   1040 <cag_strdup@plt>
mov    %rax,%rcx
mov    0x2ede(%rip),%rdx
mov    %rax,0x8(%rdx)
mov    $0x1,%eax
test   %rcx,%rcx
je     116a <cag_alloc_str_str+0x4a>
pop    %rbx
ret
mov    (%rdx),%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.str_str = type { i8*, i8* }
@cag_alloc_str_str.x = internal global %struct.str_str* null
define i32 @cag_alloc_str_str(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.str_str*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to %struct.str_str*
store %struct.str_str* %8, %struct.str_str** @cag_alloc_str_str.x
%9 = load i8*, i8** %5
%10 = bitcast i8* %9 to %struct.str_str*
store %struct.str_str* %10, %struct.str_str** %6
%11 = load %struct.str_str*, %struct.str_str** %6
%12 = getelementptr inbounds %struct.str_str, %struct.str_str* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i8* @cag_strdup(i8* %13)
%15 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%16 = getelementptr inbounds %struct.str_str, %struct.str_str* %15, i32 0, i32 0
store i8* %14, i8** %16
%17 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%18 = getelementptr inbounds %struct.str_str, %struct.str_str* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i32 0, i32* %3
br label %39
22: ; preds = %2
%23 = load %struct.str_str*, %struct.str_str** %6
%24 = getelementptr inbounds %struct.str_str, %struct.str_str* %23, i32 0, i32 1
%25 = load i8*, i8** %24
%26 = call i8* @cag_strdup(i8* %25)
%27 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%28 = getelementptr inbounds %struct.str_str, %struct.str_str* %27, i32 0, i32 1
store i8* %26, i8** %28
%29 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%30 = getelementptr inbounds %struct.str_str, %struct.str_str* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br i1 %32, label %38, label %33
33: ; preds = %22
%34 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%35 = getelementptr inbounds %struct.str_str, %struct.str_str* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @free(i8* %36)
store i32 0, i32* %3
br label %39
38: ; preds = %22
store i32 1, i32* %3
br label %39
39: ; preds = %38, %33, %21
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.str_str = type { i8*, i8* }
@cag_alloc_str_str.x = internal unnamed_addr global %struct.str_str* null
define i32 @cag_alloc_str_str(i8* %0, i8* nocapture %1) {
store i8* %0, i8** bitcast (%struct.str_str** @cag_alloc_str_str.x to i8**)
%3 = bitcast i8* %1 to i8**
%4 = load i8*, i8** %3
%5 = tail call i8* @cag_strdup(i8* %4)
%6 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%7 = getelementptr inbounds %struct.str_str, %struct.str_str* %6, i64 0, i32 0
store i8* %5, i8** %7
%8 = icmp eq i8* %5, null
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %1, i64 8
%11 = bitcast i8* %10 to i8**
%12 = load i8*, i8** %11
%13 = tail call i8* @cag_strdup(i8* %12)
%14 = load %struct.str_str*, %struct.str_str** @cag_alloc_str_str.x
%15 = getelementptr inbounds %struct.str_str, %struct.str_str* %14, i64 0, i32 1
store i8* %13, i8** %15
%16 = icmp eq i8* %13, null
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = getelementptr inbounds %struct.str_str, %struct.str_str* %14, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = tail call i32 @free(i8* %19)
br label %21
21: ; preds = %9, %2, %17
%22 = phi i32 [ 0, %17 ], [ 0, %2 ], [ 1, %9 ]
ret i32 %22
}