#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
void SetStackString2(char **ppchStack, int inStackNo, char *pchValue1,
                     char *pchValue2) {
  char *pchStack = ppchStack[inStackNo];
  if (pchValue1 != NULL && pchValue2 != NULL) {
    int inLength = strlen(pchValue1) + strlen(pchValue2);
    ppchStack[inStackNo] = malloc(inLength + 1);
    sprintf(ppchStack[inStackNo], "%s%s", pchValue1, pchValue2);
  } else {
    ppchStack[inStackNo] = NULL;
  }
  if (pchStack != NULL) {
    free(pchStack);
    pchStack = NULL;
  }
}


x86 assembly (clang, -O0):
<SetStackString2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11db <SetStackString2+0x9b>
cmpq   $0x0,-0x20(%rbp)
je     11db <SetStackString2+0x9b>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe2f(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11eb <SetStackString2+0xab>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
cmpq   $0x0,-0x28(%rbp)
je     1207 <SetStackString2+0xc7>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetStackString2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movslq %esi,%rbp
mov    (%rdi,%rbp,8),%r14
test   %rdx,%rdx
je     11b8 <SetStackString2+0x78>
mov    %rcx,%r15
test   %rcx,%rcx
je     11b8 <SetStackString2+0x78>
mov    %rdx,%r12
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r13,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1060 <sprintf@plt>
test   %r14,%r14
je     11c5 <SetStackString2+0x85>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
movq   $0x0,(%rbx,%rbp,8)
test   %r14,%r14
jne    11a2 <SetStackString2+0x62>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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