#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*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
char *str_to_lower_case(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;
  char *elementName_lower = NULL;
  elementName_lower = str_to_lower_case(elemeNtname);
  if (element != NULL)
    strSize += strlen(element) * 2;
  if (elementName_lower != NULL)
    strSize += strlen(elementName_lower);
  else {
    printf("Error. Wrong element name\n");
    return 0;
  }
  char *str = (char *)malloc(sizeof(char) * strSize);
  sprintf(str, "<%s><![CDATA[%s]]></%s>\n", elementName_lower, element,
          elementName_lower);
  bwrite = write(fd, str, strlen(str));
  free(elementName_lower);
  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)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <str_to_lower_case@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c3 <write_XML_Elemet_+0x53>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
shl    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e2 <write_XML_Elemet_+0x72>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11fa <write_XML_Elemet_+0x8a>
lea    0xe17(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1260 <write_XML_Elemet_+0xf0>
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xdf7(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
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    %edi,%r14d
mov    %rsi,%rdi
call   1080 <str_to_lower_case@plt>
mov    %rax,%rbx
test   %r15,%r15
je     11ef <write_XML_Elemet_+0x7f>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rax,1),%ebp
add    $0x32,%ebp
test   %rbx,%rbx
je     11f9 <write_XML_Elemet_+0x89>
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1207 <write_XML_Elemet_+0x97>
mov    $0x32,%ebp
test   %rbx,%rbx
jne    11a0 <write_XML_Elemet_+0x30>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"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*
%11 = 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
store i8* null, i8** %10
%12 = load i8*, i8** %6
%13 = call i8* @str_to_lower_case(i8* %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = mul nsw i32 %18, 2
%20 = load i32, i32* %9
%21 = add nsw i32 %20, %19
store i32 %21, i32* %9
br label %22
22: ; preds = %16, %3
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8*, i8** %10
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* %9
%29 = add nsw i32 %28, %27
store i32 %29, i32* %9
br label %32
30: ; preds = %22
%31 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %52
32: ; preds = %25
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = mul i64 1, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %11
%39 = load i8*, i8** %11
%40 = load i8*, i8** %10
%41 = load i8*, i8** %7
%42 = load i8*, i8** %10
%43 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %41, i8* %42)
%44 = load i32, i32* %5
%45 = load i8*, i8** %11
%46 = load i8*, i8** %11
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 %44, i8* %45, i32 %47)
store i32 %48, i32* %8
%49 = load i8*, i8** %10
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %8
store i32 %51, i32* %4
br label %52
52: ; preds = %32, %30
%53 = load i32, i32* %4
ret i32 %53
}

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