#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  scalar_t__ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int /*<<< orphan*/ sa_family;
};
struct addrinfo {
  int ai_flags;
  int ai_addrlen;
  int /*<<< orphan*/ *ai_next;
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int __u32;
typedef int __be32;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
void *__cpu_to_be32(int);
void *malloc(int);
int /*<<< orphan*/ sscanf(char const *, char *, int *, int *, int *, int *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints, struct addrinfo **res) {
  extern __u32 __ip_addr;
  struct addrinfo *resPtr = malloc(sizeof(*resPtr));
  struct sockaddr_in *addr_in = malloc(sizeof(*addr_in));
  if (!strncmp(node, "ib0", 3)) {
    addr_in->sin_addr.s_addr = __cpu_to_be32(__ip_addr);
  } else {
    int tmp[4];
    sscanf(node, "%d.%d.%d.%d", tmp + 3, tmp + 2, tmp + 1, tmp);
    __be32 addr = (tmp[3] << 24) | (tmp[2] << 16) | (tmp[1] << 8) | tmp[0];
    addr_in->sin_addr.s_addr = __cpu_to_be32(addr);
  }
  addr_in->sin_port = 0;
  resPtr->ai_flags = 40;
  resPtr->ai_family = AF_INET;
  resPtr->ai_socktype = SOCK_STREAM;
  resPtr->ai_protocol = IPPROTO_TCP;
  resPtr->ai_addrlen = sizeof(*addr_in);
  resPtr->ai_addr = (struct sockaddr *)addr_in;
  resPtr->ai_addr->sa_family = PF_INET;
  resPtr->ai_next = NULL;
  *res = resPtr;
  return 0;
}


x86 assembly (clang, -O0):
<getaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11b0 <getaddrinfo+0x70>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1030 <__cpu_to_be32@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    120b <getaddrinfo+0xcb>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
add    $0xc,%rdx
lea    -0x40(%rbp),%rcx
add    $0x8,%rcx
lea    -0x40(%rbp),%r8
add    $0x4,%r8
lea    -0x40(%rbp),%r9
lea    0xe2d(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x34(%rbp),%eax
shl    $0x18,%eax
mov    -0x38(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x3c(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   1030 <__cpu_to_be32@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x28,(%rax)
mov    0x2dc1(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    0x2d99(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    0x2d99(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x28(%rbp),%rax
movl   $0x10,0x4(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    0x2d52(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrinfo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdi,%r12
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe8e(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     11c2 <getaddrinfo+0x82>
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
lea    0xe6b(%rip),%rsi
mov    %rsp,%r9
mov    %r12,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
shl    $0x18,%eax
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%ecx
shl    $0x10,%ecx
or     %eax,%ecx
shl    $0x8,%edi
or     %ecx,%edi
or     (%rsp),%edi
jmp    11cb <getaddrinfo+0x8b>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1030 <__cpu_to_be32@plt>
mov    %rax,0x8(%r15)
movq   $0x0,(%r15)
movl   $0x28,(%rbx)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rbx)
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rbx)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rbx)
movl   $0x10,0x4(%rbx)
mov    %r15,0x10(%rbx)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r15)
movq   $0x0,0x8(%rbx)
mov    %rbx,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32*, %struct.sockaddr*, i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
@.str = [4 x i8] c"ib0\00"
@__ip_addr = external global i32
@.str.1 = [12 x i8] c"%d.%d.%d.%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@PF_INET = global i32 0
define i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo**
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.sockaddr_in*
%11 = alloca [4 x i32]
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.addrinfo* %2, %struct.addrinfo** %7
store %struct.addrinfo** %3, %struct.addrinfo*** %8
%13 = call i8* @malloc(i32 40)
%14 = bitcast i8* %13 to %struct.addrinfo*
store %struct.addrinfo* %14, %struct.addrinfo** %9
%15 = call i8* @malloc(i32 16)
%16 = bitcast i8* %15 to %struct.sockaddr_in*
store %struct.sockaddr_in* %16, %struct.sockaddr_in** %10
%17 = load i8*, i8** %5
%18 = call i32 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp ne i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %4
%21 = load i32, i32* @__ip_addr
%22 = call i8* @__cpu_to_be32(i32 %21)
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i8* %22, i8** %25
br label %55
26: ; preds = %4
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%29 = getelementptr inbounds i32, i32* %28, i64 3
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%33 = getelementptr inbounds i32, i32* %32, i64 1
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%35 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %29, i32* %31, i32* %33, i32* %34)
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%37 = load i32, i32* %36
%38 = shl i32 %37, 24
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
%40 = load i32, i32* %39
%41 = shl i32 %40, 16
%42 = or i32 %38, %41
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%44 = load i32, i32* %43
%45 = shl i32 %44, 8
%46 = or i32 %42, %45
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%48 = load i32, i32* %47
%49 = or i32 %46, %48
store i32 %49, i32* %12
%50 = load i32, i32* %12
%51 = call i8* @__cpu_to_be32(i32 %50)
%52 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %52, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i8* %51, i8** %54
br label %55
55: ; preds = %26, %20
%56 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %56, i32 0, i32 0
store i64 0, i64* %57
%58 = load %struct.addrinfo*, %struct.addrinfo** %9
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 0
store i32 40, i32* %59
%60 = load i32, i32* @AF_INET
%61 = load %struct.addrinfo*, %struct.addrinfo** %9
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 6
store i32 %60, i32* %62
%63 = load i32, i32* @SOCK_STREAM
%64 = load %struct.addrinfo*, %struct.addrinfo** %9
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i32 0, i32 5
store i32 %63, i32* %65
%66 = load i32, i32* @IPPROTO_TCP
%67 = load %struct.addrinfo*, %struct.addrinfo** %9
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 4
store i32 %66, i32* %68
%69 = load %struct.addrinfo*, %struct.addrinfo** %9
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
store i32 16, i32* %70
%71 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%72 = bitcast %struct.sockaddr_in* %71 to %struct.sockaddr*
%73 = load %struct.addrinfo*, %struct.addrinfo** %9
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 3
store %struct.sockaddr* %72, %struct.sockaddr** %74
%75 = load i32, i32* @PF_INET
%76 = load %struct.addrinfo*, %struct.addrinfo** %9
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 3
%78 = load %struct.sockaddr*, %struct.sockaddr** %77
%79 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %78, i32 0, i32 0
store i32 %75, i32* %79
%80 = load %struct.addrinfo*, %struct.addrinfo** %9
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %80, i32 0, i32 2
store i32* null, i32** %81
%82 = load %struct.addrinfo*, %struct.addrinfo** %9
%83 = load %struct.addrinfo**, %struct.addrinfo*** %8
store %struct.addrinfo* %82, %struct.addrinfo** %83
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32*, %struct.sockaddr*, i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
@.str = [4 x i8] c"ib0\00"
@__ip_addr = external global i32
@.str.1 = [12 x i8] c"%d.%d.%d.%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@PF_INET = global i32 0
define i32 @getaddrinfo(i8* %0, i8* nocapture readnone %1, %struct.addrinfo* nocapture readnone %2, %struct.addrinfo** nocapture writeonly %3) {
%5 = alloca [4 x i32]
%6 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%7 = bitcast i8* %6 to %struct.addrinfo*
%8 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%9 = bitcast i8* %8 to %struct.sockaddr_in*
%10 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i32, i32* @__ip_addr
%14 = tail call i8* @__cpu_to_be32(i32 %13)
br label %33
15: ; preds = %4
%16 = bitcast [4 x i32]* %5 to i8*
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%21 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %18, i32* %19, i32* %20, i32* %17)
%22 = load i32, i32* %18
%23 = shl i32 %22, 24
%24 = load i32, i32* %19
%25 = shl i32 %24, 16
%26 = or i32 %25, %23
%27 = load i32, i32* %20
%28 = shl i32 %27, 8
%29 = or i32 %26, %28
%30 = load i32, i32* %17
%31 = or i32 %29, %30
%32 = call i8* @__cpu_to_be32(i32 %31)
br label %33
33: ; preds = %15, %12
%34 = phi i8* [ %14, %12 ], [ %32, %15 ]
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1, i32 0
store i8* %34, i8** %35
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
store i64 0, i64* %36
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 0
store i32 40, i32* %37
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 6
store i32 %38, i32* %39
%40 = load i32, i32* @SOCK_STREAM
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 5
store i32 %40, i32* %41
%42 = load i32, i32* @IPPROTO_TCP
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 4
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 1
store i32 16, i32* %44
%45 = bitcast i8* %8 to %struct.sockaddr*
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 3
%47 = bitcast %struct.sockaddr** %46 to i8**
store i8* %8, i8** %47
%48 = load i32, i32* @PF_INET
%49 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %45, i64 0, i32 0
store i32 %48, i32* %49
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 2
store i32* null, i32** %50
%51 = bitcast %struct.addrinfo** %3 to i8**
store i8* %6, i8** %51
ret i32 0
}