#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int saveString(FILE *config_fd, char *tag, char *string, int maxlen,
               int tabbing) {
  int failureOccured = 0;
  int i = 0;
  for (i = 0; i < tabbing; i++) {
    if (fprintf(config_fd, "\t") == 0) {
      failureOccured = 1;
      break;
    }
  }
  char *temp = malloc(maxlen);
  memset(temp, 0, maxlen);
  memcpy(temp, string, maxlen);
  if (failureOccured == 0 &&
      fprintf(config_fd, "<%s>%s</%s>\n", tag, temp, tag) >= 0) {
    free(temp);
    return 0;
  }
  free(temp);
  return 1;
}


x86 assembly (clang, -O0):
<saveString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11c7 <saveString+0x77>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jne    11b4 <saveString+0x64>
movl   $0x1,-0x2c(%rbp)
jmp    11c7 <saveString+0x77>
jmp    11b9 <saveString+0x69>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1180 <saveString+0x30>
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <memcpy@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    1238 <saveString+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jl     1238 <saveString+0xe8>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1248 <saveString+0xf8>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
test   %r8d,%r8d
mov    %rdx,0x10(%rsp)
jle    11c8 <saveString+0x78>
mov    %r8d,%ebp
lea    0xe85(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rax,%rax
je     11cd <saveString+0x7d>
mov    %rbx,0x8(%rsp)
mov    $0x1,%ecx
lea    0xe65(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebx
cmp    %ecx,%ebp
je     11bb <saveString+0x6b>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x1(%rbx),%ecx
test   %rax,%rax
jne    11a0 <saveString+0x50>
cmp    %ebp,%ebx
setl   %r14b
mov    0x8(%rsp),%rbx
jmp    11d0 <saveString+0x80>
xor    %r14d,%r14d
jmp    11d0 <saveString+0x80>
mov    $0x1,%r14b
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
xor    %r13d,%r13d
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1060 <memcpy@plt>
test   %r14b,%r14b
jne    121f <saveString+0xcf>
lea    0xdfb(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rax,%rax
jns    1225 <saveString+0xd5>
mov    $0x1,%r13d
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\09\00"
@.str.1 = [13 x i8] c"<%s>%s</%s>\0A\00"
define i32 @saveString(i32* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %13
br label %15
15: ; preds = %25, %5
%16 = load i32, i32* %13
%17 = load i32, i32* %11
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32*, i32** %7
%21 = call i64 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %12
br label %28
24: ; preds = %19
br label %25
25: ; preds = %24
%26 = load i32, i32* %13
%27 = add nsw i32 %26, 1
store i32 %27, i32* %13
br label %15
28: ; preds = %23, %15
%29 = load i32, i32* %10
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %14
%31 = load i8*, i8** %14
%32 = load i32, i32* %10
%33 = call i32 @memset(i8* %31, i32 0, i32 %32)
%34 = load i8*, i8** %14
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = call i32 @memcpy(i8* %34, i8* %35, i32 %36)
%38 = load i32, i32* %12
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %28
%41 = load i32*, i32** %7
%42 = load i8*, i8** %8
%43 = load i8*, i8** %14
%44 = load i8*, i8** %8
%45 = call i64 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43, i8* %44)
%46 = icmp sge i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = load i8*, i8** %14
%49 = call i32 @free(i8* %48)
store i32 0, i32* %6
br label %53
50: ; preds = %40, %28
%51 = load i8*, i8** %14
%52 = call i32 @free(i8* %51)
store i32 1, i32* %6
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"\09\00"
@.str.1 = [13 x i8] c"<%s>%s</%s>\0A\00"
define i32 @saveString(i32* nocapture %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %19
7: ; preds = %5
%8 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7, %13
%11 = phi i32 [ %16, %13 ], [ 1, %7 ]
%12 = icmp eq i32 %11, %4
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i32 %11, 1
br i1 %15, label %17, label %10
17: ; preds = %10, %13
%18 = icmp slt i32 %11, %4
br label %19
19: ; preds = %17, %7, %5
%20 = phi i1 [ false, %5 ], [ true, %7 ], [ %18, %17 ]
%21 = tail call i8* @malloc(i32 %3)
%22 = tail call i32 @memset(i8* %21, i32 0, i32 %3)
%23 = tail call i32 @memcpy(i8* %21, i8* %2, i32 %3)
br i1 %20, label %27, label %24
24: ; preds = %19
%25 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %21, i8* %1)
%26 = icmp sgt i64 %25, -1
br i1 %26, label %28, label %27
27: ; preds = %24, %19
br label %28
28: ; preds = %24, %27
%29 = phi i32 [ 1, %27 ], [ 0, %24 ]
%30 = tail call i32 @free(i8* %21)
ret i32 %29
}