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

/* Variables and functions */
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ errx(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int main(void) {
  struct addrinfo hints, *res;
  int r;
  memset(&hints, 0, sizeof(hints));
  hints.ai_socktype = SOCK_STREAM;
  if ((r = getaddrinfo("foo.bar.google.com", "22", &hints, &res)) != 0)
    errx(1, "getaddrinfo: %s", gai_strerror(r));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    0xe8e(%rip),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1060 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11ad <main+0x6d>
mov    -0x14(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe6e(%rip),%rsi
call   1030 <errx@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0xe96(%rip),%rdi
lea    0xea2(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdx
call   1060 <getaddrinfo@plt>
test   %eax,%eax
je     119c <main+0x5c>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe86(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1030 <errx@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"foo.bar.google.com\00"
@.str.1 = [3 x i8] c"22\00"
@.str.2 = [16 x i8] c"getaddrinfo: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 4)
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 0
store i32 %6, i32* %7
%8 = call i32 @getaddrinfo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
store i32 %8, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* %4
%12 = call i32 @gai_strerror(i32 %11)
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %0
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"foo.bar.google.com\00"
@.str.1 = [3 x i8] c"22\00"
@.str.2 = [16 x i8] c"getaddrinfo: %s\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 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 4)
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
store i32 %6, i32* %7
%8 = call i32 @getaddrinfo(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @gai_strerror(i32 %8)
%12 = call i32 @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %0
ret i32 0
}