#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char const *, char const *);
int strlen(char const *);
char *BuildClause(const char *format, const char *arg, int *length) {
  int argLength, formatLength, formats;
  char *clause;
  *length = 0;
  if (arg == NULL)
    return "";
  formats = 1;
  argLength = strlen(arg);
  formatLength = strlen(format);
  *length = formatLength + argLength - (formats * 2);
  clause = malloc(*length + 1);
  sprintf(clause, format, arg);
  return clause;
}


x86 assembly (clang, -O0):
<BuildClause>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <BuildClause+0x39>
lea    0xea0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <BuildClause+0x97>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
add    -0x24(%rbp),%ecx
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
sub    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BuildClause>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rdx)
test   %rsi,%rsi
je     1185 <BuildClause+0x55>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%ecx
add    $0xfffffffe,%ecx
mov    %ecx,(%r15)
lea    (%rax,%rbx,1),%edi
add    $0xffffffff,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sprintf@plt>
jmp    118c <BuildClause+0x5c>
lea    0xe74(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @BuildClause(i8* %0, i8* %1, i32* nocapture writeonly %2) {
store i32 0, i32* %2
%4 = icmp eq i8* %1, null
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, %6
%9 = add nsw i32 %8, -2
store i32 %9, i32* %2
%10 = add nsw i32 %8, -1
%11 = tail call i8* @malloc(i32 %10)
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) %0, i8* %1)
br label %13
13: ; preds = %3, %5
%14 = phi i8* [ %11, %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %3 ]
ret i8* %14
}