#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 *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int,
                            char const *);
int strlen(char const *);
char *build_url(const char *host, int port, const char *path) {
  char *url;
  int len;
  len = strlen(host) + strlen(path) + 14;
  url = malloc(len);
  if (url == NULL)
    return NULL;
  snprintf(url, len, "http://%s:%d%s", host, port, path);
  return url;
}


x86 assembly (clang, -O0):
<build_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0xe,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1189 <build_url+0x59>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <build_url+0x80>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    0xe5d(%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):
<build_url>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0xe,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117f <build_url+0x4f>
lea    0xe94(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rcx
mov    %r14d,%r8d
mov    %r15,%r9
call   1040 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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