#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*/ assert(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
size_t strlen(char const *);
char *xmalloc(size_t);
char *concat_path(const char *dir, const char *rel_path) {
  size_t length1 = strlen(dir);
  size_t length2 = strlen(rel_path);
  size_t length_result = length1 + 1 + length2;
  char *s = xmalloc(length_result + 1);
  sprintf(s, "%s/%s", dir, rel_path);
  assert(strlen(s) == length_result);
  return s;
}


x86 assembly (clang, -O0):
<concat_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe62(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%r12
add    $0x1,%r12
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1040 <xmalloc@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    %r12,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
define i8* @concat_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = add i64 %13, 1
%15 = load i64, i64* %6
%16 = add i64 %14, %15
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = add i64 %17, 1
%19 = call i8* @xmalloc(i64 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %8
%25 = call i64 @strlen(i8* %24)
%26 = load i64, i64* %7
%27 = icmp eq i64 %25, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i8*, i8** %8
ret i8* %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i8* @concat_path(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 1
%6 = add i64 %5, %4
%7 = add i64 %6, 1
%8 = tail call i8* @xmalloc(i64 %7)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%11 = icmp eq i64 %10, %6
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
ret i8* %8
}