#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int strlen(char *);
int write(int, char *, int);
int write_XML_Elemet(int fd, char *elemeNtname, char *element) {
  int bwrite = 0;
  int strSize = 50;
  if (element != NULL)
    strSize += strlen(element) * 2;
  if (elemeNtname != NULL)
    strSize += strlen(elemeNtname);
  else {
    printf("*** ZVM Error. Wrong element name\n");
    return 0;
  }
  char *str = (char *)malloc(sizeof(char) * strSize);
  sprintf(str, "<%s><![CDATA[%s]]></%s>\n", elemeNtname, element, elemeNtname);
  bwrite = write(fd, str, strlen(str));
  return bwrite;
}


x86 assembly (clang, -O0):
<write_XML_Elemet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x32,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <write_XML_Elemet+0x3e>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ad <write_XML_Elemet+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <write_XML_Elemet+0x75>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1222 <write_XML_Elemet+0xd2>
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe34(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_XML_Elemet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r14d
test   %rdx,%rdx
je     11c3 <write_XML_Elemet+0x73>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,1),%ebp
add    $0x32,%ebp
test   %rbx,%rbx
je     11cd <write_XML_Elemet+0x7d>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <write@plt>
mov    $0x32,%ebp
test   %rbx,%rbx
jne    1178 <write_XML_Elemet+0x28>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"*** ZVM Error. Wrong element name\0A\00"
@.str.1 = [25 x i8] c"<%s><![CDATA[%s]]></%s>\0A\00"
define i32 @write_XML_Elemet(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
store i32 50, i32* %9
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = mul nsw i32 %15, 2
%17 = load i32, i32* %9
%18 = add nsw i32 %17, %16
store i32 %18, i32* %9
br label %19
19: ; preds = %13, %3
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = load i32, i32* %9
%26 = add nsw i32 %25, %24
store i32 %26, i32* %9
br label %29
27: ; preds = %19
%28 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %47
29: ; preds = %22
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = load i8*, i8** %6
%38 = load i8*, i8** %7
%39 = load i8*, i8** %6
%40 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38, i8* %39)
%41 = load i32, i32* %5
%42 = load i8*, i8** %10
%43 = load i8*, i8** %10
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @write(i32 %41, i8* %42, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
store i32 %46, i32* %4
br label %47
47: ; preds = %29, %27
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"<%s><![CDATA[%s]]></%s>\0A\00"
@str = [34 x i8] c"*** ZVM Error. Wrong element name\00"
define i32 @write_XML_Elemet(i32 %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %2)
%7 = shl nsw i32 %6, 1
%8 = add nsw i32 %7, 50
br label %9
9: ; preds = %5, %3
%10 = phi i32 [ %8, %5 ], [ 50, %3 ]
%11 = icmp eq i8* %1, null
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %1)
%14 = add nsw i32 %13, %10
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2, i8* %1)
%18 = tail call i32 @strlen(i8* %16)
%19 = tail call i32 @write(i32 %0, i8* %16, i32 %18)
br label %22
20: ; preds = %9
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %12, %20
%23 = phi i32 [ %19, %12 ], [ 0, %20 ]
ret i32 %23
}