#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_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
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*/ perror(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  int status;
  int sockfd;
  ssize_t read_bytes;
  struct addrinfo *servinfo, hints;
  char buffer[BUFSIZ];
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if ((status = getaddrinfo("raspberrypi.local", "6666", &hints, &servinfo)) !=
      0) {
    fprintf(stderr, "getaddrinfo() error: %s\n", gai_strerror(status));
    return 1;
  }
  if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,
                       servinfo->ai_protocol)) == -1) {
    perror("socket() error");
    return 1;
  }
  if (connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    perror("connect() error");
    return 1;
  }
  freeaddrinfo(servinfo);
  while ((read_bytes = read(0, buffer, BUFSIZ)) > 0) {
    send(sockfd, buffer, read_bytes, 0);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xde6(%rip),%rdi
lea    0xdf1(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1273 <main+0xc3>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xdbc(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    134a <main+0x19a>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12b8 <main+0x108>
lea    0xd90(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    134a <main+0x19a>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12f5 <main+0x145>
lea    0xd62(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    134a <main+0x19a>
mov    -0x18(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    -0x50(%rbp),%rsi
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    1334 <main+0x184>
mov    -0x50(%rbp),%rsi
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
jmp    12fe <main+0x14e>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r12
mov    0x2dfd(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x48(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    0xdee(%rip),%rdi
lea    0xdf9(%rip),%rsi
lea    -0x30(%rbp),%rcx
mov    %r14,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
je     1252 <main+0xa2>
mov    0x2da8(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xdd7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%r15d
jmp    12cb <main+0x11b>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x130>
mov    %eax,%r14d
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r14d,%edi
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     12e9 <main+0x139>
mov    -0x30(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    0x0(%r13),%edx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <read@plt>
test   %eax,%eax
jle    12c3 <main+0x113>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    0x0(%r13),%edx
jmp    12a0 <main+0xf0>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %r12,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd49(%rip),%rdi
jmp    12f0 <main+0x140>
lea    0xd4f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%r15d
jmp    12cb <main+0x11b>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [18 x i8] c"raspberrypi.local\00"
@.str.1 = [5 x i8] c"6666\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"getaddrinfo() error: %s\0A\00"
@.str.3 = [15 x i8] c"socket() error\00"
@.str.4 = [16 x i8] c"connect() error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 20)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %17, i32* %18
%19 = call i32 @getaddrinfo(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %5)
store i32 %19, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = load i32, i32* %2
%24 = call i8* @gai_strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 1, i32* %1
store i32 1, i32* %9
br label %66
26: ; preds = %0
%27 = load %struct.addrinfo*, %struct.addrinfo** %5
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 4
%29 = load i32, i32* %28
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 3
%32 = load i32, i32* %31
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %29, i32 %32, i32 %35)
store i32 %36, i32* %3
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %26
%39 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %9
br label %66
40: ; preds = %26
%41 = load i32, i32* %3
%42 = load %struct.addrinfo*, %struct.addrinfo** %5
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 1
%44 = load i32, i32* %43
%45 = load %struct.addrinfo*, %struct.addrinfo** %5
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @connect(i32 %41, i32 %44, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %40
%51 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %9
br label %66
52: ; preds = %40
%53 = load %struct.addrinfo*, %struct.addrinfo** %5
%54 = call i32 @freeaddrinfo(%struct.addrinfo* %53)
br label %55
55: ; preds = %59, %52
%56 = load i32, i32* @BUFSIZ
%57 = call i32 @read(i32 0, i8* %13, i32 %56)
store i32 %57, i32* %4
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* %3
%61 = load i32, i32* %4
%62 = call i32 @send(i32 %60, i8* %13, i32 %61, i32 0)
br label %55
63: ; preds = %55
%64 = load i32, i32* %3
%65 = call i32 @close(i32 %64)
store i32 0, i32* %1
store i32 1, i32* %9
br label %66
66: ; preds = %63, %50, %38, %21
%67 = load i8*, i8** %7
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [18 x i8] c"raspberrypi.local\00"
@.str.1 = [5 x i8] c"6666\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"getaddrinfo() error: %s\0A\00"
@.str.3 = [15 x i8] c"socket() error\00"
@.str.4 = [16 x i8] c"connect() error\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 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 20)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
store i32 %12, i32* %13
%14 = call i32 @getaddrinfo(i8* getelementptr inbounds ([18 x i8], [18 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** %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = call i8* @gai_strerror(i32 %14)
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %56
20: ; preds = %0
%21 = load %struct.addrinfo*, %struct.addrinfo** %1
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 4
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 3
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 2
%27 = load i32, i32* %26
%28 = call i32 @socket(i32 %23, i32 %25, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %56
32: ; preds = %20
%33 = load %struct.addrinfo*, %struct.addrinfo** %1
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @connect(i32 %28, i32 %35, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %56
42: ; preds = %32
%43 = load %struct.addrinfo*, %struct.addrinfo** %1
%44 = call i32 @freeaddrinfo(%struct.addrinfo* %43)
%45 = load i32, i32* @BUFSIZ
%46 = call i32 @read(i32 0, i8* %8, i32 %45)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %42, %48
%49 = phi i32 [ %52, %48 ], [ %46, %42 ]
%50 = call i32 @send(i32 %28, i8* %8, i32 %49, i32 0)
%51 = load i32, i32* @BUFSIZ
%52 = call i32 @read(i32 0, i8* %8, i32 %51)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %48, label %54
54: ; preds = %48, %42
%55 = call i32 @close(i32 %28)
br label %56
56: ; preds = %54, %40, %30, %16
%57 = phi i32 [ 1, %16 ], [ 1, %30 ], [ 1, %40 ], [ 0, %54 ]
ret i32 %57
}