#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*/ ENOENT;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int xml_read_attribute_copy(char const **, char const *, char **);
int set_mandatory_attribute(struct xml_reader *reader, const char *elem,
                            const char **attrs, struct manifest_tpk *manif,
                            char **data, const char *name) {
  int status;
  assert(!*data);
  status = xml_read_attribute_copy(attrs, name, data);
  if (status < 0)
    return -1;
  if (status)
    return 0;
  errno = ENOENT;
  return -1;
}


x86 assembly (clang, -O0):
<set_mandatory_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <xml_read_attribute_copy@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1181 <set_mandatory_attribute+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <set_mandatory_attribute+0x90>
cmpl   $0x0,-0x3c(%rbp)
je     1197 <set_mandatory_attribute+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <set_mandatory_attribute+0x90>
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    0x2e39(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mandatory_attribute>:
push   %r15
push   %r14
push   %rbx
mov    %r9,%r14
mov    %r8,%rbx
mov    %rdx,%r15
xor    %edi,%edi
cmpq   $0x0,(%r8)
sete   %dil
call   1040 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <xml_read_attribute_copy@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
js     1173 <set_mandatory_attribute+0x53>
xor    %eax,%eax
test   %ecx,%ecx
jne    1173 <set_mandatory_attribute+0x53>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    0x2e74(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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