#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 */
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
char *string_alloc(scalar_t__);
scalar_t__ string_length(char *);
char *smt_ternary(char *opt, char *op1, char *op2, char *op3) {
  char *string;
  string = string_alloc(1 + string_length(opt) + 1 + string_length(op1) + 1 +
                        string_length(op2) + 1 + string_length(op3) + 1);
  sprintf(string, "(%s %s %s %s)", opt, op1, op2, op3);
  return string;
}


x86 assembly (clang, -O0):
<smt_ternary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <string_length@plt>
add    $0x1,%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <string_length@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <string_length@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <string_length@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1030 <string_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe35(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smt_ternary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <string_length@plt>
mov    %rax,(%rsp)
mov    %r12,%rdi
call   1040 <string_length@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <string_length@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <string_length@plt>
add    (%rsp),%rbp
add    %r14,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x5,%rdi
call   1030 <string_alloc@plt>
mov    %rax,%rbp
lea    0xe74(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1050 <sprintf@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"(%s %s %s %s)\00"
define i8* @smt_ternary(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i64 @string_length(i8* %0)
%6 = tail call i64 @string_length(i8* %1)
%7 = tail call i64 @string_length(i8* %2)
%8 = tail call i64 @string_length(i8* %3)
%9 = add i64 %5, 5
%10 = add i64 %9, %6
%11 = add i64 %10, %7
%12 = add i64 %11, %8
%13 = tail call i8* @string_alloc(i64 %12)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i8* %3)
ret i8* %13
}