#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 ai_family;
  int ai_socktype;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AI_PASSIVE;
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
int idrnet_getaddrinfo(struct addrinfo **address_res, char *host, int port,
                       int family, int socket_type) {
  struct addrinfo hints;
  char str_port[8];
  sprintf(str_port, "%d", port);
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = family;
  hints.ai_socktype = socket_type;
  if (strlen(host) == 0) {
    hints.ai_flags = AI_PASSIVE;
    return getaddrinfo(NULL, str_port, &hints, address_res);
  }
  return getaddrinfo(host, str_port, &hints, address_res);
}


x86 assembly (clang, -O0):
<idrnet_getaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe98(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    11c5 <idrnet_getaddrinfo+0x85>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x4(%rbp)
jmp    11dd <idrnet_getaddrinfo+0x9d>
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idrnet_getaddrinfo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeb4(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1040 <sprintf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    %ebp,(%rsp)
mov    %r15d,0x4(%rsp)
cmpb   $0x0,(%rbx)
je     117f <idrnet_getaddrinfo+0x4f>
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
jmp    1196 <idrnet_getaddrinfo+0x66>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
xor    %edi,%edi
mov    %r14,%rcx
call   1050 <getaddrinfo@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@AI_PASSIVE = global i32 0
define i32 @idrnet_getaddrinfo(%struct.addrinfo** %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.addrinfo**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.addrinfo
%13 = alloca [8 x i8]
store %struct.addrinfo** %0, %struct.addrinfo*** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%15 = load i32, i32* %9
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @memset(%struct.addrinfo* %12, i32 0, i32 12)
%18 = load i32, i32* %10
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %11
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i8*, i8** %8
%23 = call i64 @strlen(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %5
%26 = load i32, i32* @AI_PASSIVE
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 2
store i32 %26, i32* %27
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%29 = load %struct.addrinfo**, %struct.addrinfo*** %7
%30 = call i32 @getaddrinfo(i8* null, i8* %28, %struct.addrinfo* %12, %struct.addrinfo** %29)
store i32 %30, i32* %6
br label %36
31: ; preds = %5
%32 = load i8*, i8** %8
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%34 = load %struct.addrinfo**, %struct.addrinfo*** %7
%35 = call i32 @getaddrinfo(i8* %32, i8* %33, %struct.addrinfo* %12, %struct.addrinfo** %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %31, %25
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@AI_PASSIVE = global i32 0
define i32 @idrnet_getaddrinfo(%struct.addrinfo** %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.addrinfo
%7 = alloca [8 x i8]
%8 = bitcast %struct.addrinfo* %6 to i8*
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%11 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 12)
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
store i32 %3, i32* %12
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
store i32 %4, i32* %13
%14 = load i8, i8* %1
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %5
%17 = load i32, i32* @AI_PASSIVE
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @getaddrinfo(i8* null, i8* %9, %struct.addrinfo* %6, %struct.addrinfo** %0)
br label %22
20: ; preds = %5
%21 = call i32 @getaddrinfo(i8* %1, i8* %9, %struct.addrinfo* %6, %struct.addrinfo** %0)
br label %22
22: ; preds = %20, %16
%23 = phi i32 [ %19, %16 ], [ %21, %20 ]
ret i32 %23
}