#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*/ check_malloc(void *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
unsigned long strlen(char *);
void canonicalise_item(char *item_name, char *path, int path_len,
                       char **item_p) {
  int newsize;
  char *non_canonicalised_item;
  unsigned long item_name_len = strlen(item_name);
  newsize = (int)(path_len + 1 + item_name_len + 1);
  non_canonicalised_item = malloc(sizeof(char) * (newsize));
  check_malloc((void *)non_canonicalised_item);
  strcpy(non_canonicalised_item, path);
  strcat(non_canonicalised_item, "/");
  strcat(non_canonicalised_item, item_name);
  *item_p = strdup(non_canonicalised_item);
  free(non_canonicalised_item);
}


x86 assembly (clang, -O0):
<canonicalise_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
add    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <check_malloc@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonicalise_item>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <check_malloc@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define void @canonicalise_item(i8* %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %11
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = load i64, i64* %11
%18 = add i64 %16, %17
%19 = add i64 %18, 1
%20 = trunc i64 %19 to i32
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = call i32 @check_malloc(i8* %26)
%28 = load i8*, i8** %10
%29 = load i8*, i8** %6
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %10
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = load i8*, i8** %10
%34 = load i8*, i8** %5
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %10
%37 = call i8* @strdup(i8* %36)
%38 = load i8**, i8*** %8
store i8* %37, i8** %38
%39 = load i8*, i8** %10
%40 = call i32 @free(i8* %39)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @canonicalise_item(i8* %0, i8* %1, i32 %2, i8** nocapture writeonly %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = add i32 %2, 2
%8 = add i32 %7, %6
%9 = tail call i8* @malloc(i32 %8)
%10 = tail call i32 @check_malloc(i8* %9)
%11 = tail call i32 @strcpy(i8* %9, i8* %1)
%12 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %9, i8* %0)
%14 = tail call i8* @strdup(i8* %9)
store i8* %14, i8** %3
%15 = tail call i32 @free(i8* %9)
ret void
}