#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 xml_reader {
  int dummy;
};
struct manifest_tpk {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EEXIST;
int /*<<< orphan*/ errno;
int fail_out_of_memory();
char *strndup(char const *, int);
int set_simple_string_once(struct xml_reader *reader, const char *ch, int len,
                           struct manifest_tpk *manif, char **data,
                           const char *name) {
  if (*data) {
    errno = EEXIST;
    return -1;
  }
  *data = strndup(ch, len);
  if (!*data)
    return fail_out_of_memory();
  return 0;
}


x86 assembly (clang, -O0):
<set_simple_string_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     116b <set_simple_string_once+0x4b>
mov    0x2e8c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <set_simple_string_once+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <strndup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119e <set_simple_string_once+0x7e>
mov    $0x0,%al
call   1040 <fail_out_of_memory@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <set_simple_string_once+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_simple_string_once>:
push   %rbx
cmpq   $0x0,(%r8)
je     1140 <set_simple_string_once+0x20>
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    0x2ea1(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    %r8,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <strndup@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
xor    %eax,%eax
test   %rcx,%rcx
je     115c <set_simple_string_once+0x3c>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
jmp    1040 <fail_out_of_memory@plt>

LLVM IR (-O0):
%struct.xml_reader = type { i32 }
%struct.manifest_tpk = type { i32 }
@EEXIST = global i32 0
@errno = global i32 0
define i32 @set_simple_string_once(%struct.xml_reader* %0, i8* %1, i32 %2, %struct.manifest_tpk* %3, i8** %4, i8* %5) {
%7 = alloca i32
%8 = alloca %struct.xml_reader*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.manifest_tpk*
%12 = alloca i8**
%13 = alloca i8*
store %struct.xml_reader* %0, %struct.xml_reader** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store %struct.manifest_tpk* %3, %struct.manifest_tpk** %11
store i8** %4, i8*** %12
store i8* %5, i8** %13
%14 = load i8**, i8*** %12
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = load i32, i32* @EEXIST
store i32 %18, i32* @errno
store i32 -1, i32* %7
br label %30
19: ; preds = %6
%20 = load i8*, i8** %9
%21 = load i32, i32* %10
%22 = call i8* @strndup(i8* %20, i32 %21)
%23 = load i8**, i8*** %12
store i8* %22, i8** %23
%24 = load i8**, i8*** %12
%25 = load i8*, i8** %24
%26 = icmp ne i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %19
%28 = call i32 (...) @fail_out_of_memory()
store i32 %28, i32* %7
br label %30
29: ; preds = %19
store i32 0, i32* %7
br label %30
30: ; preds = %29, %27, %17
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
%struct.xml_reader = type { i32 }
%struct.manifest_tpk = type { i32 }
@EEXIST = global i32 0
@errno = global i32 0
define i32 @set_simple_string_once(%struct.xml_reader* nocapture readnone %0, i8* nocapture %1, i32 %2, %struct.manifest_tpk* nocapture readnone %3, i8** nocapture %4, i8* nocapture readnone %5) {
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = load i32, i32* @EEXIST
store i32 %10, i32* @errno
br label %16
11: ; preds = %6
%12 = tail call i8* @strndup(i8* %1, i32 %2)
store i8* %12, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (...) @fail_out_of_memory()
br label %16
16: ; preds = %11, %14, %9
%17 = phi i32 [ -1, %9 ], [ %15, %14 ], [ 0, %11 ]
ret i32 %17
}