#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void log_begin_xml(FILE *fd, const char *binary, int argc, char **args) {
  int i;
  fprintf(fd, "<syscalltrace>\n");
  fprintf(fd, "  <process>\n");
  fprintf(fd, "    <binary>%s</binary>\n", binary);
  if (argc > 0) {
    fprintf(fd, "    <arguments>\n");
    for (i = 0; i < argc; ++i) {
      fprintf(fd, "      <arg>%s</arg>\n", args[i]);
    }
    fprintf(fd, "    </arguments>\n");
  } else {
    fprintf(fd, "    <arguments/>\n");
  }
  fprintf(fd, "  </process>\n");
  fprintf(fd, "  <trace>\n");
}


x86 assembly (clang, -O0):
<log_begin_xml>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xece(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xecc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xec3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11d3 <log_begin_xml+0xc3>
mov    -0x8(%rbp),%rdi
lea    0xec0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bc <log_begin_xml+0xac>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <log_begin_xml+0x74>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e5 <log_begin_xml+0xd5>
mov    -0x8(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_begin_xml>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r12
lea    0xec2(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fwrite@plt>
lea    0xeb9(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fwrite@plt>
lea    0xead(%rip),%rsi
mov    %r12,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %r15d,%r15d
jle    11cc <log_begin_xml+0xac>
lea    0xead(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fwrite@plt>
mov    %r15d,%ebx
lea    0xea2(%rip),%r13
lea    0xeb0(%rip),%r15
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r14,%rbp,8),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11b0 <log_begin_xml+0x90>
jmp    11d3 <log_begin_xml+0xb3>
lea    0xe9b(%rip),%r15
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r12,%rcx
call   1040 <fwrite@plt>
lea    0xe91(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fwrite@plt>
lea    0xe86(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"<syscalltrace>\0A\00"
@.str.1 = [13 x i8] c" <process>\0A\00"
@.str.2 = [25 x i8] c" <binary>%s</binary>\0A\00"
@.str.3 = [17 x i8] c" <arguments>\0A\00"
@.str.4 = [21 x i8] c" <arg>%s</arg>\0A\00"
@.str.5 = [18 x i8] c" </arguments>\0A\00"
@.str.6 = [18 x i8] c" <arguments/>\0A\00"
@.str.7 = [14 x i8] c" </process>\0A\00"
@.str.8 = [11 x i8] c" <trace>\0A\00"
define void @log_begin_xml(i32* %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
%10 = load i32*, i32** %5
%11 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = load i32*, i32** %5
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32*, i32** %5
%15 = load i8*, i8** %6
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %4
%20 = load i32*, i32** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %9
br label %22
22: ; preds = %34, %19
%23 = load i32, i32* %9
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i32*, i32** %5
%28 = load i8**, i8*** %8
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %22
37: ; preds = %22
%38 = load i32*, i32** %5
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %43
40: ; preds = %4
%41 = load i32*, i32** %5
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %40, %37
%44 = load i32*, i32** %5
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32*, i32** %5
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"<syscalltrace>\0A\00"
@.str.1 = [13 x i8] c" <process>\0A\00"
@.str.2 = [25 x i8] c" <binary>%s</binary>\0A\00"
@.str.3 = [17 x i8] c" <arguments>\0A\00"
@.str.4 = [21 x i8] c" <arg>%s</arg>\0A\00"
@.str.5 = [18 x i8] c" </arguments>\0A\00"
@.str.6 = [18 x i8] c" <arguments/>\0A\00"
@.str.7 = [14 x i8] c" </process>\0A\00"
@.str.8 = [11 x i8] c" <trace>\0A\00"
define void @log_begin_xml(i32* nocapture %0, i8* %1, i32 %2, i8** nocapture %3) {
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15, i64 1, i32* %0)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 12, i64 1, i32* %0)
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 16, i64 1, i32* %0)
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %17, %12 ]
%14 = getelementptr inbounds i8*, i8** %3, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %4
%20 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %4 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), %12 ]
%21 = tail call i64 @fwrite(i8* %20, i64 17, i64 1, i32* %0)
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i64 13, i64 1, i32* %0)
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 10, i64 1, i32* %0)
ret void
}