#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*/ sprintf(char *, 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);
  sprintf(newstr, "%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   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a6 <ut_aux_build_url+0x76>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <ut_aux_build_url+0x96>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe47(%rip),%rsi
call   1050 <sprintf@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   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
cmpb   $0x2f,(%rsi)
sete   %bl
add    %rsi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1181 <ut_aux_build_url+0x51>
lea    0xe8d(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
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 %32
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
%31 = load i8*, i8** %7
store i8* %31, i8** %3
br label %32
32: ; preds = %26, %25
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define noalias 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 @sprintf(i8* %11, i8* dereferenceable(1) 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
}