#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_addrlen;
  scalar_t__ ai_next;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res;
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  int error = getaddrinfo(NULL, "0", &hints, &res);
  if (error) {
    printf("error %d\n", error);
  } else {
    printf("error %d\n", error);
  }
  if (res->ai_next) {
    printf("res->ai_next");
    freeaddrinfo(res);
  } else {
    printf("addre len %d\n", res->ai_addrlen);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe8b(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1040 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11a5 <main+0x75>
mov    -0x3c(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <main+0x86>
mov    -0x3c(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11e1 <main+0xb1>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <freeaddrinfo@plt>
jmp    11f5 <main+0xc5>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0xe9e(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
xor    %edi,%edi
call   1040 <getaddrinfo@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rax
cmpq   $0x0,0x8(%rax)
je     11a5 <main+0x75>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rdi
call   1050 <freeaddrinfo@plt>
jmp    11b5 <main+0x85>
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [2 x i8] c"0\00"
@.str.1 = [10 x i8] c"error %d\0A\00"
@.str.2 = [13 x i8] c"res->ai_next\00"
@.str.3 = [14 x i8] c"addre len %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %7, i32* %8
%9 = load i32, i32* @SOCK_DGRAM
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %9, i32* %10
%11 = load i32, i32* @AI_PASSIVE
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load %struct.addrinfo*, %struct.addrinfo** %4
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 1
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = load %struct.addrinfo*, %struct.addrinfo** %4
%22 = call i32 @freeaddrinfo(%struct.addrinfo* %21)
br label %27
23: ; preds = %2
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %19
ret i32 0
}