#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 */
scalar_t__ malloc(int);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *logic_cond(char *cond1, char *logic, char *cond2) {
  int size = strlen(cond1) + strlen(cond2);
  char *result = (char *)malloc(strlen(logic) + size + 2 + 1);
  strcpy(result, "(");
  strcat(strcat(strcat(strcat(result, cond1), logic), cond2), ")");
  return result;
}


x86 assembly (clang, -O0):
<logic_cond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    -0x1c(%rbp),%edi
add    $0x2,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,%rdi
lea    0xe33(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logic_cond>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe7f(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movw   $0x29,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"(\00"
@.str.1 = [2 x i8] c")\00"
define i8* @logic_cond(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
store i32 %13, i32* %7
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
%18 = add nsw i32 %17, 2
%19 = add nsw i32 %18, 1
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %8
%25 = load i8*, i8** %4
%26 = call i8* @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = call i8* @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = call i8* @strcat(i8* %28, i8* %29)
%31 = call i8* @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8*, i8** %8
ret i8* %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"(\00"
define i8* @logic_cond(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %2)
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %4, 3
%8 = add i32 %7, %5
%9 = add i32 %8, %6
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = tail call i8* @strcat(i8* dereferenceable(1) %11, i8* dereferenceable(1) %0)
%14 = tail call i8* @strcat(i8* dereferenceable(1) %11, i8* dereferenceable(1) %1)
%15 = tail call i8* @strcat(i8* dereferenceable(1) %11, i8* dereferenceable(1) %2)
%16 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %11)
%17 = getelementptr i8, i8* %11, i64 %16
%18 = bitcast i8* %17 to i16*
store i16 41, i16* %18
ret i8* %11
}