#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 snprintf(char *, int, char *, char *, char const *, char *);
int strlen(char const *);
char *allocate_general_path(char *parent, char *file, const char *sep) {
  int res, len = strlen(parent) + strlen(file) + strlen(sep) + 1;
  char *path = malloc(len);
  if (path != NULL) {
    res = snprintf(path, len, "%s%s%s", parent, sep, file);
    if (res == len - 1)
      return path;
    else
      free(path);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<allocate_general_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ee <allocate_general_path+0xae>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe46(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11e0 <allocate_general_path+0xa0>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f6 <allocate_general_path+0xb6>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11ee <allocate_general_path+0xae>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_general_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
add    %r14d,%ebx
mov    %rbp,(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    (%r14,%rbx,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b8 <allocate_general_path+0x78>
mov    %rax,%r13
add    %r14d,%ebx
lea    0xe68(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r12,%rcx
mov    (%rsp),%r8
mov    %r15,%r9
call   1050 <snprintf@plt>
cmp    %ebx,%eax
je     11bb <allocate_general_path+0x7b>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define i8* @allocate_general_path(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, %4
%7 = tail call i32 @strlen(i8* %2)
%8 = add nsw i32 %6, %7
%9 = add nsw i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = tail call i32 @snprintf(i8* %10, i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2, i8* %1)
%14 = icmp eq i32 %13, %8
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @free(i8* %10)
br label %17
17: ; preds = %3, %15, %12
%18 = phi i8* [ %10, %12 ], [ null, %15 ], [ null, %3 ]
ret i8* %18
}