#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 */
char *add(char *, char *);
int strlen(char *);
char *mcomp_add(unsigned long flags, char *s1, char *s2) {
  char *dp;
  if (!(flags & 0x000200))
    return add(s1, s2);
  if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
    *dp = 0;
  return add(s1, add(",\n", s2));
}


x86 assembly (clang, -O0):
<mcomp_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
and    $0x200,%rax
cmp    $0x0,%rax
jne    115e <mcomp_add+0x3e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <add@plt>
mov    %rax,-0x8(%rbp)
jmp    11ce <mcomp_add+0xae>
cmpq   $0x0,-0x20(%rbp)
je     11a6 <mcomp_add+0x86>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    %rax,%rdx
add    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11a6 <mcomp_add+0x86>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1030 <add@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1030 <add@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcomp_add>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
test   $0x200,%edi
je     115f <mcomp_add+0x3f>
test   %rbx,%rbx
je     114d <mcomp_add+0x2d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rbx,%rax,1)
jne    114d <mcomp_add+0x2d>
movb   $0x0,-0x1(%rbx,%rax,1)
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
call   1030 <add@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <add@plt>

LLVM IR (-O0):
@.str = [3 x i8] c",\0A\00"
define i8* @mcomp_add(i64 %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i64, i64* %5
%10 = and i64 %9, 512
%11 = icmp ne i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = call i8* @add(i8* %13, i8* %14)
store i8* %15, i8** %4
br label %36
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -1
store i8* %25, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = load i8*, i8** %8
store i8 0, i8* %30
br label %31
31: ; preds = %29, %19, %16
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i8* @add(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = call i8* @add(i8* %32, i8* %34)
store i8* %35, i8** %4
br label %36
36: ; preds = %31, %12
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
@.str = [3 x i8] c",\0A\00"
define i8* @mcomp_add(i64 %0, i8* %1, i8* %2) {
%4 = and i64 %0, 512
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = icmp eq i8* %2, null
br i1 %7, label %16, label %8
8: ; preds = %6
%9 = tail call i32 @strlen(i8* %2)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %8
store i8 0, i8* %12
br label %16
16: ; preds = %15, %8, %6
%17 = tail call i8* @add(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %18
18: ; preds = %3, %16
%19 = phi i8* [ %17, %16 ], [ %2, %3 ]
%20 = tail call i8* @add(i8* %1, i8* %19)
ret i8* %20
}