#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
typedef int /*<<< orphan*/ host;

/* Variables and functions */
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
char *fmt_http_host(struct sockaddr_in addr) {
  static char host[] = "123.123.123.123:12345";
  if (ntohs(addr.sin_port) == 80)
    return inet_ntoa(addr.sin_addr);
  else {
    snprintf(host, sizeof(host), "%s:%u", inet_ntoa(addr.sin_addr),
             ntohs(addr.sin_port));
    return host;
  }
}


x86 assembly (clang, -O0):
<fmt_http_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <ntohs@plt>
cmp    $0x50,%eax
jne    115e <fmt_http_host+0x2e>
mov    -0xc(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x8(%rbp)
jmp    119c <fmt_http_host+0x6c>
mov    -0xc(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <ntohs@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,%r8d
lea    0x2ec0(%rip),%rdi
mov    $0x16,%esi
lea    0xe74(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ea8(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_http_host>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %rdi,%rbx
shr    $0x20,%rbx
call   1050 <ntohs@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
cmp    $0x50,%ebp
je     1183 <fmt_http_host+0x53>
mov    %r15d,%edi
call   1050 <ntohs@plt>
lea    0x2eda(%rip),%rbx
lea    0xe93(%rip),%rdx
mov    %rbx,%rdi
mov    $0x16,%esi
mov    %r14,%rcx
mov    %eax,%r8d
call   1040 <snprintf@plt>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@fmt_http_host.host = internal global [22 x i8] c"123.123.123.123:12345\00"
@.str = [6 x i8] c"%s:%u\00"
define i8* @fmt_http_host(i64 %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i64*
store i64 %0, i64* %4
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%6 = load i32, i32* %5
%7 = call i32 @ntohs(i32 %6)
%8 = icmp eq i32 %7, 80
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i8* @inet_ntoa(i32 %11)
store i8* %12, i8** %2
br label %21
13: ; preds = %1
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i8* @inet_ntoa(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = call i32 @snprintf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @fmt_http_host.host, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %19)
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @fmt_http_host.host, i64 0, i64 0), i8** %2
br label %21
21: ; preds = %13, %9
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@fmt_http_host.host = internal global [22 x i8] c"123.123.123.123:12345\00"
@.str = [6 x i8] c"%s:%u\00"
define i8* @fmt_http_host(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = lshr i64 %0, 32
%4 = trunc i64 %3 to i32
%5 = tail call i32 @ntohs(i32 %2)
%6 = icmp eq i32 %5, 80
%7 = tail call i8* @inet_ntoa(i32 %4)
br i1 %6, label %11, label %8
8: ; preds = %1
%9 = tail call i32 @ntohs(i32 %2)
%10 = tail call i32 @snprintf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @fmt_http_host.host, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %9)
br label %11
11: ; preds = %1, %8
%12 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @fmt_http_host.host, i64 0, i64 0), %8 ], [ %7, %1 ]
ret i8* %12
}