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


x86 assembly (clang, -O0):
<write_XML_Element_Size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x32,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <str_to_lower_case@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ed <write_XML_Element_Size+0x6d>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
shl    $0x1,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     120c <write_XML_Element_Size+0x8c>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1224 <write_XML_Element_Size+0xa4>
lea    0xded(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1307 <write_XML_Element_Size+0x187>
mov    -0x20(%rbp),%rax
add    $0x32,%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdbd(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
add    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd88(%rip),%rsi
call   10a0 <sprintf@plt>
movslq -0x3c(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
add    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_XML_Element_Size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %edi,%ebx
mov    %rsi,%rdi
call   1090 <str_to_lower_case@plt>
mov    %rax,%r13
test   %r12,%r12
je     11ab <write_XML_Element_Size+0x2b>
mov    %r12,%rdi
call   1060 <strlen@plt>
test   %r13,%r13
je     124c <write_XML_Element_Size+0xcc>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
lea    (%r15,%rax,2),%edi
add    $0x32,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
lea    0xe26(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,0x4(%rsp)
movslq %eax,%rbx
lea    (%rbx,%rbp,1),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <memcpy@plt>
add    %r15,%r14
lea    0xdfe(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
add    %r15d,%ebx
add    %eax,%ebx
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    125a <write_XML_Element_Size+0xda>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"*** ZVM Error. Wrong element name\0A\00"
@.str.1 = [14 x i8] c"<%s><![CDATA[\00"
@.str.2 = [10 x i8] c"]]></%s>\0A\00"
define i32 @write_XML_Element_Size(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32 0, i32* %10
store i32 50, i32* %11
store i8* null, i8** %12
store i8* null, i8** %13
%16 = load i8*, i8** %7
%17 = call i8* @str_to_lower_case(i8* %16)
store i8* %17, i8** %13
store i32 0, i32* %14
store i32 0, i32* %15
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %4
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = mul nsw i32 %22, 2
%24 = load i32, i32* %11
%25 = add nsw i32 %24, %23
store i32 %25, i32* %11
br label %26
26: ; preds = %20, %4
%27 = load i8*, i8** %13
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %13
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %11
%33 = add nsw i32 %32, %31
store i32 %33, i32* %11
br label %36
34: ; preds = %26
%35 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %91
36: ; preds = %29
%37 = load i64, i64* %9
%38 = add i64 50, %37
%39 = load i8*, i8** %13
%40 = call i32 @strlen(i8* %39)
%41 = mul nsw i32 %40, 2
%42 = sext i32 %41 to i64
%43 = add i64 %38, %42
%44 = mul i64 1, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = load i8*, i8** %13
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %12
%52 = call i32 @strlen(i8* %51)
store i32 %52, i32* %14
%53 = load i8*, i8** %12
%54 = load i32, i32* %14
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8*, i8** %8
%58 = load i64, i64* %9
%59 = call i32 @memcpy(i8* %56, i8* %57, i64 %58)
%60 = load i8*, i8** %12
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i64, i64* %9
%65 = getelementptr inbounds i8, i8* %63, i64 %64
%66 = load i8*, i8** %13
%67 = call i32 @sprintf(i8* %65, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %66)
%68 = load i32, i32* %14
%69 = sext i32 %68 to i64
%70 = load i64, i64* %9
%71 = add i64 %69, %70
%72 = load i8*, i8** %12
%73 = load i32, i32* %14
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i64, i64* %9
%77 = getelementptr inbounds i8, i8* %75, i64 %76
%78 = call i32 @strlen(i8* %77)
%79 = sext i32 %78 to i64
%80 = add i64 %71, %79
%81 = trunc i64 %80 to i32
store i32 %81, i32* %15
%82 = load i32, i32* %6
%83 = load i8*, i8** %12
%84 = load i32, i32* %15
%85 = call i32 @write(i32 %82, i8* %83, i32 %84)
store i32 %85, i32* %10
%86 = load i8*, i8** %12
%87 = call i32 @free(i8* %86)
%88 = load i8*, i8** %13
%89 = call i32 @free(i8* %88)
%90 = load i32, i32* %10
store i32 %90, i32* %5
br label %91
91: ; preds = %36, %34
%92 = load i32, i32* %5
ret i32 %92
}

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