#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, short);
scalar_t__ strlen(char const *);
int Create_Http_Header_Host_String(const char *host, short int port,
                                   char **request_host) {
  if (port > 16383) {
    return -897;
  }
  *request_host = (char *)malloc(1 + strlen(host) + 5 + 1);
  if (NULL == *request_host) {
    return -499;
  }
  (void)sprintf(*request_host, "%s:%d", host, port);
  return 0;
}


x86 assembly (clang, -O0):
<Create_Http_Header_Host_String>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %rdx,-0x20(%rbp)
movswl -0x12(%rbp),%eax
cmp    $0x3fff,%eax
jle    1162 <Create_Http_Header_Host_String+0x32>
movl   $0xfffffc7f,-0x4(%rbp)
jmp    11c6 <Create_Http_Header_Host_String+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
add    $0x5,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    11a4 <Create_Http_Header_Host_String+0x74>
movl   $0xfffffe0d,-0x4(%rbp)
jmp    11c6 <Create_Http_Header_Host_String+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe4a(%rip),%rsi
movswl -0x12(%rbp),%ecx
call   1050 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Create_Http_Header_Host_String>:
push   %rbp
push   %r14
push   %rbx
mov    $0xfffffc7f,%eax
cmp    $0x3fff,%esi
jg     117d <Create_Http_Header_Host_String+0x4d>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x7(%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1178 <Create_Http_Header_Host_String+0x48>
movswl %bp,%ecx
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
xor    %eax,%eax
jmp    117d <Create_Http_Header_Host_String+0x4d>
mov    $0xfffffe0d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s:%d\00"
define i32 @Create_Http_Header_Host_String(i8* %0, i16 signext %1, i8** nocapture writeonly %2) {
%4 = icmp sgt i16 %1, 16383
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 7
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %2
%10 = icmp eq i64 %8, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i16 signext %1)
br label %13
13: ; preds = %5, %3, %11
%14 = phi i32 [ 0, %11 ], [ -897, %3 ], [ -499, %5 ]
ret i32 %14
}