#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*/ EINVAL;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
char *malloc(size_t);
int snprintf(char *, size_t, char *, char const *, char const *);
int strlen(char const *);
char *cfg_make_fullpath(const char *dir, const char *file) {
  int np;
  char *path;
  size_t len;
  if (!dir || !file) {
    errno = EINVAL;
    return NULL;
  }
  len = strlen(dir) + strlen(file) + 2;
  path = malloc(len);
  if (!path)
    return NULL;
  np = snprintf(path, len, "%s/%s", dir, file);
  assert(np < (int)len);
  return path;
}


x86 assembly (clang, -O0):
<cfg_make_fullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <cfg_make_fullpath+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1185 <cfg_make_fullpath+0x45>
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6a(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    120c <cfg_make_fullpath+0xcc>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <cfg_make_fullpath+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    120c <cfg_make_fullpath+0xcc>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe1a(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    %ecx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_make_fullpath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a7 <cfg_make_fullpath+0x67>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a7 <cfg_make_fullpath+0x67>
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b9 <cfg_make_fullpath+0x79>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
xor    %edi,%edi
cmp    %r12d,%eax
setl   %dil
call   1050 <assert@plt>
jmp    11bb <cfg_make_fullpath+0x7b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    0x2e29(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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