#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 *misc_malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *append_parmline(char *a, char *b) {
  char *buffer;
  int insert_blank;
  if (strlen(a) == 0)
    insert_blank = 0;
  else
    insert_blank = (a[strlen(a) - 1] != ' ');
  buffer = misc_malloc(strlen(a) + strlen(b) + (insert_blank ? 2 : 1));
  if (buffer != NULL) {
    if (insert_blank)
      sprintf(buffer, "%s %s", a, b);
    else
      sprintf(buffer, "%s%s", a, b);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<append_parmline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    115e <append_parmline+0x2e>
movl   $0x0,-0x1c(%rbp)
jmp    118d <append_parmline+0x5d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
add    %eax,%edi
mov    -0x1c(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    %eax,%edi
call   1040 <misc_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1214 <append_parmline+0xe4>
cmpl   $0x0,-0x1c(%rbp)
je     11f7 <append_parmline+0xc7>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe13(%rip),%rsi
call   1050 <sprintf@plt>
jmp    120f <append_parmline+0xdf>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdfc(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1214 <append_parmline+0xe4>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_parmline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
je     115c <append_parmline+0x2c>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x20,-0x1(%rax,%r15,1)
sete   %bpl
jmp    115f <append_parmline+0x2f>
mov    $0x1,%bpl
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
test   %bpl,%bpl
je     1193 <append_parmline+0x63>
add    $0x1,%eax
mov    %eax,%edi
call   1040 <misc_malloc@plt>
test   %rax,%rax
je     11bc <append_parmline+0x8c>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
jmp    11ac <append_parmline+0x7c>
add    $0x2,%eax
mov    %eax,%edi
call   1040 <misc_malloc@plt>
test   %rax,%rax
je     11bc <append_parmline+0x8c>
mov    %rax,%rbx
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
jmp    11be <append_parmline+0x8e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @append_parmline(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %6
br label %22
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 32
%21 = zext i1 %20 to i32
store i32 %21, i32* %6
br label %22
22: ; preds = %11, %10
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %24, %26
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 2, i32 1
%32 = add nsw i32 %27, %31
%33 = call i8* @misc_malloc(i32 %32)
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %50
36: ; preds = %22
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8*, i8** %5
%41 = load i8*, i8** %3
%42 = load i8*, i8** %4
%43 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %42)
br label %49
44: ; preds = %36
%45 = load i8*, i8** %5
%46 = load i8*, i8** %3
%47 = load i8*, i8** %4
%48 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %44, %39
br label %50
50: ; preds = %49, %22
%51 = load i8*, i8** %5
ret i8* %51
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [5 x i8] c"%s%s\00"
define i8* @append_parmline(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
br label %12
12: ; preds = %2, %5
%13 = phi i1 [ %11, %5 ], [ true, %2 ]
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strlen(i8* %1)
%16 = add nsw i32 %15, %14
br i1 %13, label %17, label %21
17: ; preds = %12
%18 = add nsw i32 %16, 1
%19 = tail call i8* @misc_malloc(i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %29, label %27
21: ; preds = %12
%22 = add nsw i32 %16, 2
%23 = tail call i8* @misc_malloc(i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = tail call i32 @sprintf(i8* %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %29
27: ; preds = %17
%28 = tail call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %29
29: ; preds = %21, %25, %27, %17
%30 = phi i8* [ null, %21 ], [ %23, %25 ], [ %19, %27 ], [ null, %17 ]
ret i8* %30
}