#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  scalar_t__ ai_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int init_cache_expire(char *htcphost) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int sfd, s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(htcphost, "4827", &hints, &result);
  if (s != 0) {
    syslog(LOG_ERR, "Failed to lookup HTCP cache host: %s", gai_strerror(s));
    return -1;
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (sfd == -1)
      continue;
    if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
      break;
    close(sfd);
  }
  if (rp == NULL) {
    syslog(LOG_ERR, "Failed to create HTCP cache socket");
    return -1;
  }
  freeaddrinfo(result);
  return sfd;
}


x86 assembly (clang, -O0):
<init_cache_expire>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     121c <init_cache_expire+0x9c>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
mov    %eax,%edx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <init_cache_expire+0x155>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1298 <init_cache_expire+0x118>
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdx
call   10a0 <socket@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    125c <init_cache_expire+0xdc>
jmp    1287 <init_cache_expire+0x107>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
je     127f <init_cache_expire+0xff>
jmp    1298 <init_cache_expire+0x118>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1224 <init_cache_expire+0xa4>
cmpq   $0x0,-0x48(%rbp)
jne    12c6 <init_cache_expire+0x146>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <init_cache_expire+0x155>
mov    -0x40(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_cache_expire>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe2e(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     120d <init_cache_expire+0x8d>
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe0a(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%ebp
jmp    1280 <init_cache_expire+0x100>
mov    (%rsp),%rbx
jmp    1224 <init_cache_expire+0xa4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1259 <init_cache_expire+0xd9>
mov    0x14(%rbx),%edi
mov    0x10(%rbx),%esi
mov    0x8(%rbx),%rdx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1220 <init_cache_expire+0xa0>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    1277 <init_cache_expire+0xf7>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1220 <init_cache_expire+0xa0>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%ebp
jmp    1280 <init_cache_expire+0x100>
mov    (%rsp),%rdi
call   1090 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"4827\00"
@LOG_ERR = global i32 0
@.str.1 = [37 x i8] c"Failed to lookup HTCP cache host: %s\00"
@.str.2 = [35 x i8] c"Failed to create HTCP cache socket\00"
define i32 @init_cache_expire(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 40)
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 6
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 2
store i64 0, i64* %15
%16 = load i8*, i8** %3
%17 = call i32 @getaddrinfo(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = load i32, i32* @LOG_ERR
%22 = load i32, i32* %8
%23 = call i32 @gai_strerror(i32 %22)
%24 = call i32 (i32, i8*, ...) @syslog(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 -1, i32* %2
br label %72
25: ; preds = %1
%26 = load %struct.addrinfo*, %struct.addrinfo** %5
store %struct.addrinfo* %26, %struct.addrinfo** %6
br label %27
27: ; preds = %58, %25
%28 = load %struct.addrinfo*, %struct.addrinfo** %6
%29 = icmp ne %struct.addrinfo* %28, null
br i1 %29, label %30, label %62
30: ; preds = %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %6
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %6
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = load %struct.addrinfo*, %struct.addrinfo** %6
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 2
%39 = load i64, i64* %38
%40 = call i32 @socket(i32 %33, i32 %36, i64 %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %30
br label %58
44: ; preds = %30
%45 = load i32, i32* %7
%46 = load %struct.addrinfo*, %struct.addrinfo** %6
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %6
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @connect(i32 %45, i32 %48, i32 %51)
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %55
54: ; preds = %44
br label %62
55: ; preds = %44
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
br label %58
58: ; preds = %55, %43
%59 = load %struct.addrinfo*, %struct.addrinfo** %6
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 5
%61 = load %struct.addrinfo*, %struct.addrinfo** %60
store %struct.addrinfo* %61, %struct.addrinfo** %6
br label %27
62: ; preds = %54, %27
%63 = load %struct.addrinfo*, %struct.addrinfo** %6
%64 = icmp eq %struct.addrinfo* %63, null
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* @LOG_ERR
%67 = call i32 (i32, i8*, ...) @syslog(i32 %66, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %72
68: ; preds = %62
%69 = load %struct.addrinfo*, %struct.addrinfo** %5
%70 = call i32 @freeaddrinfo(%struct.addrinfo* %69)
%71 = load i32, i32* %7
store i32 %71, i32* %2
br label %72
72: ; preds = %68, %65, %20
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, %struct.addrinfo*, i64 }
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"4827\00"
@LOG_ERR = global i32 0
@.str.1 = [37 x i8] c"Failed to lookup HTCP cache host: %s\00"
@.str.2 = [35 x i8] c"Failed to create HTCP cache socket\00"
define i32 @init_cache_expire(i8* %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo* %2 to i8*
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 40)
%7 = load i32, i32* @AF_UNSPEC
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_DGRAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 6
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 2
store i64 0, i64* %12
%13 = call i32 @getaddrinfo(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load %struct.addrinfo*, %struct.addrinfo** %3
%17 = icmp eq %struct.addrinfo* %16, null
br i1 %17, label %45, label %22
18: ; preds = %1
%19 = load i32, i32* @LOG_ERR
%20 = call i32 @gai_strerror(i32 %13)
%21 = call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %51
22: ; preds = %15, %41
%23 = phi %struct.addrinfo* [ %43, %41 ], [ %16, %15 ]
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 2
%29 = load i64, i64* %28
%30 = call i32 @socket(i32 %25, i32 %27, i64 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %41, label %32
32: ; preds = %22
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @connect(i32 %30, i32 %34, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %48
39: ; preds = %32
%40 = call i32 @close(i32 %30)
br label %41
41: ; preds = %22, %39
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 5
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %22
45: ; preds = %41, %15
%46 = load i32, i32* @LOG_ERR
%47 = call i32 (i32, i8*, ...) @syslog(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %51
48: ; preds = %32
%49 = load %struct.addrinfo*, %struct.addrinfo** %3
%50 = call i32 @freeaddrinfo(%struct.addrinfo* %49)
br label %51
51: ; preds = %48, %45, %18
%52 = phi i32 [ -1, %18 ], [ -1, %45 ], [ %30, %48 ]
ret i32 %52
}