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

/* Variables and functions */
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  struct addrinfo hints, *res;
  int i, ret;
  mtrace();
  for (i = 0; i < 100; i++) {
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    ret = getaddrinfo("www.gnu.org", "http", &hints, &res);
    if (ret) {
      printf("%s\n", gai_strerror(ret));
      return 1;
    }
    freeaddrinfo(res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <mtrace@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    1211 <main+0xb1>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe4f(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11fa <main+0x9a>
mov    -0x20(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xb8>
mov    -0x18(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <main+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1060 <mtrace@plt>
mov    $0x64,%ebp
lea    0x8(%rsp),%rbx
mov    0x2e52(%rip),%r13
lea    0xe73(%rip),%r14
lea    0xe78(%rip),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
jne    11ec <main+0x8c>
mov    0x10(%rsp),%rdi
call   1080 <freeaddrinfo@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x40>
xor    %eax,%eax
jmp    1207 <main+0xa7>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe17(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"www.gnu.org\00"
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (...) @mtrace()
store i32 0, i32* %4
br label %7
7: ; preds = %26, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 8)
%12 = load i32, i32* @PF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @getaddrinfo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* %5
%21 = call i8* @gai_strerror(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
store i32 1, i32* %1
br label %30
23: ; preds = %10
%24 = load %struct.addrinfo*, %struct.addrinfo** %3
%25 = call i32 @freeaddrinfo(%struct.addrinfo* %24)
br label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %7
29: ; preds = %7
store i32 0, i32* %1
br label %30
30: ; preds = %29, %19
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"www.gnu.org\00"
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = bitcast %struct.addrinfo* %1 to i8*
%4 = bitcast %struct.addrinfo** %2 to i8*
%5 = tail call i32 (...) @mtrace()
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
br label %8
8: ; preds = %0, %18
%9 = phi i32 [ 0, %0 ], [ %21, %18 ]
%10 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 8)
%11 = load i32, i32* @PF_UNSPEC
store i32 %11, i32* %6
%12 = load i32, i32* @SOCK_STREAM
store i32 %12, i32* %7
%13 = call i32 @getaddrinfo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = call i8* @gai_strerror(i32 %13)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %23
18: ; preds = %8
%19 = load %struct.addrinfo*, %struct.addrinfo** %2
%20 = call i32 @freeaddrinfo(%struct.addrinfo* %19)
%21 = add nuw nsw i32 %9, 1
%22 = icmp eq i32 %21, 100
br i1 %22, label %23, label %8
23: ; preds = %18, %15
%24 = phi i32 [ 1, %15 ], [ 0, %18 ]
ret i32 %24
}