#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 */
char *calloc(int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int strlen(char const *);
char *ut_aux_build_url(const char *host, const char *path) {
  int buflen;
  char *newstr;
  if (*path == '/')
    path++;
  buflen = strlen(host) + strlen(path) + 2;
  if ((newstr = calloc(buflen, sizeof(char))) == NULL)
    return (NULL);
  snprintf(newstr, buflen, "%s/%s", host, path);
  return (newstr);
}


x86 assembly (clang, -O0):
<ut_aux_build_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    115c <ut_aux_build_url+0x2c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a6 <ut_aux_build_url+0x76>
movq   $0x0,-0x8(%rbp)
jmp    11c9 <ut_aux_build_url+0x99>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe44(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ut_aux_build_url>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
cmpb   $0x2f,(%rsi)
sete   %bl
add    %rsi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%r15d
add    $0x2,%r15d
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1189 <ut_aux_build_url+0x59>
lea    0xe88(%rip),%rdx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1040 <snprintf@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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