#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 sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int EXIT_FAILURE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int sockfd, numbytes;
  char buf[100];
  struct addrinfo hints, *servinfo, *p;
  int rv;
  char s[INET6_ADDRSTRLEN];
  int i = 0;
  if (argc != 2) {
    fprintf(stderr, "usage: client hostname\n");
    exit(1);
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((rv = getaddrinfo(argv[1], "3490", &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 1;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("client: socket");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("client: connect");
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "client: failed to connect\n");
    return 2;
  }
  inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s,
            sizeof s);
  printf("client: connecting to %s\n", s);
  freeaddrinfo(servinfo);
  char **ename = (char **)malloc(4 * sizeof(char *));
  char buff[16];
  pid_t ffdf;
  while (i < 4) {
    *(ename + i) = (char *)malloc(128 * sizeof(char));
    ++i;
  }
  strcpy(*(ename + 0), "/home/kawaguchi/system-c/week4/record/client/record");
  strcpy(*(ename + 1), "-");
  *(ename + 2) = (char *)NULL;
  int pipes[2];
  if (pipe(pipes)) {
    close(sockfd);
    perror("pipe");
    exit(EXIT_FAILURE);
  }
  ffdf = fork();
  if (!ffdf) {
    close(pipes[0]);
    if (dup2(pipes[1], STDOUT_FILENO) == -1) {
      close(pipes[1]);
      perror("dup2");
      exit(EXIT_FAILURE);
    }
    execvp(*ename, ename);
    perror("execvp");
    exit(EXIT_FAILURE);
  } else {
    close(pipes[1]);
    i = 0;
    while (read(pipes[0], buff, 16) > 0)
      send(sockfd, buff, 16, 0);
    close(sockfd);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x110(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x108(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xc8(%rbp)
movl   $0x0,-0xcc(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     12da <main+0x8a>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10a0 <memset@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcfe(%rip),%rsi
lea    -0xa0(%rbp),%rdx
lea    -0xa8(%rbp),%rcx
call   1140 <getaddrinfo@plt>
mov    %eax,-0xb4(%rbp)
cmp    $0x0,%eax
je     1383 <main+0x133>
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    -0xb4(%rbp),%edi
call   1090 <gai_strerror@plt>
mov    -0x114(%rbp),%edi
mov    %rax,%rdx
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0xd0(%rbp)
jmp    169d <main+0x44d>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
je     1439 <main+0x1e9>
mov    -0xb0(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0xb0(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0xb0(%rbp),%rax
mov    0x10(%rax),%edx
call   1170 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    13df <main+0x18f>
lea    0xc59(%rip),%rdi
call   1100 <perror@plt>
jmp    1422 <main+0x1d2>
mov    -0x14(%rbp),%edi
mov    -0xb0(%rbp),%rax
mov    (%rax),%rsi
mov    -0xb0(%rbp),%rax
mov    0xc(%rax),%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    141d <main+0x1cd>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xc2a(%rip),%rdi
call   1100 <perror@plt>
jmp    1422 <main+0x1d2>
jmp    1439 <main+0x1e9>
mov    -0xb0(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0xb0(%rbp)
jmp    1391 <main+0x141>
cmpq   $0x0,-0xb0(%rbp)
jne    1474 <main+0x224>
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
lea    0xbf6(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0xd0(%rbp)
jmp    169d <main+0x44d>
mov    -0xb0(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x118(%rbp)
mov    -0xb0(%rbp),%rax
mov    (%rax),%rdi
call   1040 <get_in_addr@plt>
mov    -0x118(%rbp),%edi
mov    -0x108(%rbp),%rdx
mov    %eax,%esi
mov    -0x110(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x108(%rbp),%rsi
lea    0xbaa(%rip),%rdi
call   1080 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1160 <freeaddrinfo@plt>
mov    $0x20,%edi
call   10f0 <malloc@plt>
mov    %rax,-0xd8(%rbp)
cmpl   $0x4,-0xcc(%rbp)
jge    1520 <main+0x2d0>
mov    $0x80,%edi
call   10f0 <malloc@plt>
mov    %rax,%rdx
mov    -0xd8(%rbp),%rax
movslq -0xcc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
jmp    14e0 <main+0x290>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rdi
lea    0xb51(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0xd8(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb6e(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0xd8(%rbp),%rax
movq   $0x0,0x10(%rax)
lea    -0xfc(%rbp),%rdi
call   10c0 <pipe@plt>
cmp    $0x0,%rax
je     1594 <main+0x344>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xb37(%rip),%rdi
call   1100 <perror@plt>
mov    0x2a2b(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    $0x0,%al
call   1150 <fork@plt>
mov    %eax,-0xf4(%rbp)
cmpl   $0x0,-0xf4(%rbp)
jne    162b <main+0x3db>
mov    -0xfc(%rbp),%edi
call   10b0 <close@plt>
mov    -0xf8(%rbp),%edi
mov    0x2a2a(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0xffffffff,%eax
jne    15fb <main+0x3ab>
mov    -0xf8(%rbp),%edi
call   10b0 <close@plt>
lea    0xad5(%rip),%rdi
call   1100 <perror@plt>
mov    0x29c4(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xd8(%rbp),%rsi
call   1110 <execvp@plt>
lea    0xaaa(%rip),%rdi
call   1100 <perror@plt>
mov    0x2994(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0xf8(%rbp),%edi
call   10b0 <close@plt>
movl   $0x0,-0xcc(%rbp)
mov    -0xfc(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <read@plt>
cmp    $0x0,%rax
jle    167c <main+0x42c>
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1640 <main+0x3f0>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xd0(%rbp)
mov    -0xc0(%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    $0x48,%rsp
mov    %rsp,%r13
mov    0x2d75(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r14
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x2,%edi
jne    14bb <main+0x26b>
mov    %rsi,%rbx
lea    -0x70(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10a0 <memset@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x8(%rbx),%rdi
lea    0xd57(%rip),%rsi
lea    -0x40(%rbp),%rcx
mov    %r12,%rdx
call   1140 <getaddrinfo@plt>
test   %eax,%eax
je     12fe <main+0xae>
mov    0x2cf0(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <gai_strerror@plt>
lea    0xd35(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%eax
jmp    14a9 <main+0x259>
mov    %r13,-0x38(%rbp)
mov    -0x40(%rbp),%r13
test   %r13,%r13
je     135f <main+0x10f>
lea    0xd1c(%rip),%rbx
mov    0x14(%r13),%esi
mov    0x8(%r13),%edi
mov    0x10(%r13),%edx
call   1170 <socket@plt>
mov    %rbx,%rdi
cmp    $0xffffffff,%eax
je     1351 <main+0x101>
mov    %eax,%r12d
mov    0x0(%r13),%rsi
mov    0xc(%r13),%edx
mov    %eax,%edi
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    1384 <main+0x134>
mov    %r12d,%edi
call   10b0 <close@plt>
lea    0xcec(%rip),%rdi
call   1100 <perror@plt>
mov    0x18(%r13),%r13
test   %r13,%r13
jne    1312 <main+0xc2>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x2,%eax
mov    -0x38(%rbp),%r13
jmp    14a9 <main+0x259>
mov    0x8(%r13),%ebx
mov    0x0(%r13),%rdi
call   1040 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
lea    0xcc1(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1160 <freeaddrinfo@plt>
mov    $0x20,%edi
call   10f0 <malloc@plt>
mov    %rax,%r14
mov    $0x80,%edi
call   10f0 <malloc@plt>
mov    %rax,(%r14)
mov    $0x80,%edi
call   10f0 <malloc@plt>
mov    %rax,0x8(%r14)
mov    $0x80,%edi
call   10f0 <malloc@plt>
mov    %rax,0x10(%r14)
mov    $0x80,%edi
call   10f0 <malloc@plt>
mov    %rax,0x18(%r14)
mov    (%r14),%rdi
lea    0xc7c(%rip),%rsi
call   1050 <strcpy@plt>
mov    0x8(%r14),%rdi
lea    0xca0(%rip),%rsi
call   1050 <strcpy@plt>
movq   $0x0,0x10(%r14)
lea    -0x30(%rbp),%rdi
call   10c0 <pipe@plt>
test   %rax,%rax
jne    14dc <main+0x28c>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
mov    -0x38(%rbp),%r13
je     14ed <main+0x29d>
mov    -0x2c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x30(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <read@plt>
test   %rax,%rax
jle    1497 <main+0x247>
lea    -0x50(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x30(%rbp),%edi
mov    %rbx,%rsi
mov    $0x10,%edx
call   10d0 <read@plt>
test   %rax,%rax
jg     1470 <main+0x220>
mov    %r12d,%edi
call   10b0 <close@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
lea    0xb35(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
lea    0xbcd(%rip),%rdi
jmp    152e <main+0x2de>
mov    -0x30(%rbp),%edi
call   10b0 <close@plt>
mov    -0x2c(%rbp),%edi
mov    0x2af1(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0xffffffff,%eax
jne    151c <main+0x2cc>
mov    -0x2c(%rbp),%edi
call   10b0 <close@plt>
lea    0xba3(%rip),%rdi
jmp    152e <main+0x2de>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1110 <execvp@plt>
lea    0xb94(%rip),%rdi
call   1100 <perror@plt>
mov    0x2a7e(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"3490\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [15 x i8] c"client: socket\00"
@.str.4 = [16 x i8] c"client: connect\00"
@.str.5 = [27 x i8] c"client: failed to connect\0A\00"
@.str.6 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.7 = [52 x i8] c"/home/kawaguchi/system-c/week4/record/client/record\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.10 = [5 x i8] c"dup2\00"
@.str.11 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8**
%18 = alloca [16 x i8]
%19 = alloca i32
%20 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %13
%24 = alloca i8, i64 %22
store i64 %22, i64* %14
store i32 0, i32* %15
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 2
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
%32 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 32)
%33 = load i32, i32* @AF_UNSPEC
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store i32 %33, i32* %34
%35 = load i32, i32* @SOCK_STREAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @getaddrinfo(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %40, i32* %12
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %31
%43 = load i32, i32* @stderr
%44 = load i32, i32* %12
%45 = call i8* @gai_strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %45)
store i32 1, i32* %3
store i32 1, i32* %16
br label %187
47: ; preds = %31
%48 = load %struct.addrinfo*, %struct.addrinfo** %10
store %struct.addrinfo* %48, %struct.addrinfo** %11
br label %49
49: ; preds = %81, %47
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = icmp ne %struct.addrinfo* %50, null
br i1 %51, label %52, label %85
52: ; preds = %49
%53 = load %struct.addrinfo*, %struct.addrinfo** %11
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %11
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 4
%58 = load i32, i32* %57
%59 = load %struct.addrinfo*, %struct.addrinfo** %11
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 3
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %55, i32 %58, i32 %61)
store i32 %62, i32* %6
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %52
%65 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %81
66: ; preds = %52
%67 = load i32, i32* %6
%68 = load %struct.addrinfo*, %struct.addrinfo** %11
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 0
%70 = load i64, i64* %69
%71 = load %struct.addrinfo*, %struct.addrinfo** %11
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 2
%73 = load i32, i32* %72
%74 = call i32 @connect(i32 %67, i64 %70, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %80
76: ; preds = %66
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %81
80: ; preds = %66
br label %85
81: ; preds = %76, %64
%82 = load %struct.addrinfo*, %struct.addrinfo** %11
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 5
%84 = load %struct.addrinfo*, %struct.addrinfo** %83
store %struct.addrinfo* %84, %struct.addrinfo** %11
br label %49
85: ; preds = %80, %49
%86 = load %struct.addrinfo*, %struct.addrinfo** %11
%87 = icmp eq %struct.addrinfo* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
store i32 1, i32* %16
br label %187
91: ; preds = %85
%92 = load %struct.addrinfo*, %struct.addrinfo** %11
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 1
%94 = load i32, i32* %93
%95 = load %struct.addrinfo*, %struct.addrinfo** %11
%96 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %95, i32 0, i32 0
%97 = load i64, i64* %96
%98 = inttoptr i64 %97 to %struct.sockaddr*
%99 = call i32 @get_in_addr(%struct.sockaddr* %98)
%100 = trunc i64 %22 to i32
%101 = call i32 @inet_ntop(i32 %94, i32 %99, i8* %24, i32 %100)
%102 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%103 = load %struct.addrinfo*, %struct.addrinfo** %10
%104 = call i32 @freeaddrinfo(%struct.addrinfo* %103)
%105 = call i64 @malloc(i32 32)
%106 = inttoptr i64 %105 to i8**
store i8** %106, i8*** %17
br label %107
107: ; preds = %110, %91
%108 = load i32, i32* %15
%109 = icmp slt i32 %108, 4
br i1 %109, label %110, label %119
110: ; preds = %107
%111 = call i64 @malloc(i32 128)
%112 = inttoptr i64 %111 to i8*
%113 = load i8**, i8*** %17
%114 = load i32, i32* %15
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8*, i8** %113, i64 %115
store i8* %112, i8** %116
%117 = load i32, i32* %15
%118 = add nsw i32 %117, 1
store i32 %118, i32* %15
br label %107
119: ; preds = %107
%120 = load i8**, i8*** %17
%121 = getelementptr inbounds i8*, i8** %120, i64 0
%122 = load i8*, i8** %121
%123 = call i32 @strcpy(i8* %122, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%124 = load i8**, i8*** %17
%125 = getelementptr inbounds i8*, i8** %124, i64 1
%126 = load i8*, i8** %125
%127 = call i32 @strcpy(i8* %126, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%128 = load i8**, i8*** %17
%129 = getelementptr inbounds i8*, i8** %128, i64 2
store i8* null, i8** %129
%130 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%131 = call i64 @pipe(i32* %130)
%132 = icmp ne i64 %131, 0
br i1 %132, label %133, label %139
133: ; preds = %119
%134 = load i32, i32* %6
%135 = call i32 @close(i32 %134)
%136 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%137 = load i32, i32* @EXIT_FAILURE
%138 = call i32 @exit(i32 %137)
unreachable
139: ; preds = %119
%140 = call i32 (...) @fork()
store i32 %140, i32* %19
%141 = load i32, i32* %19
%142 = icmp ne i32 %141, 0
br i1 %142, label %167, label %143
143: ; preds = %139
%144 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%145 = load i32, i32* %144
%146 = call i32 @close(i32 %145)
%147 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%148 = load i32, i32* %147
%149 = load i32, i32* @STDOUT_FILENO
%150 = call i32 @dup2(i32 %148, i32 %149)
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %159
152: ; preds = %143
%153 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%154 = load i32, i32* %153
%155 = call i32 @close(i32 %154)
%156 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%157 = load i32, i32* @EXIT_FAILURE
%158 = call i32 @exit(i32 %157)
unreachable
159: ; preds = %143
%160 = load i8**, i8*** %17
%161 = load i8*, i8** %160
%162 = load i8**, i8*** %17
%163 = call i32 @execvp(i8* %161, i8** %162)
%164 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%165 = load i32, i32* @EXIT_FAILURE
%166 = call i32 @exit(i32 %165)
unreachable
167: ; preds = %139
%168 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%169 = load i32, i32* %168
%170 = call i32 @close(i32 %169)
store i32 0, i32* %15
br label %171
171: ; preds = %177, %167
%172 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%173 = load i32, i32* %172
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%175 = call i64 @read(i32 %173, i8* %174, i32 16)
%176 = icmp sgt i64 %175, 0
br i1 %176, label %177, label %181
177: ; preds = %171
%178 = load i32, i32* %6
%179 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%180 = call i32 @send(i32 %178, i8* %179, i32 16, i32 0)
br label %171
181: ; preds = %171
%182 = load i32, i32* %6
%183 = call i32 @close(i32 %182)
br label %184
184: ; preds = %181
%185 = load i32, i32* %6
%186 = call i32 @close(i32 %185)
store i32 0, i32* %3
store i32 1, i32* %16
br label %187
187: ; preds = %184, %88, %42
%188 = load i8*, i8** %13
%189 = load i32, i32* %3
ret i32 %189
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"usage: client hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [5 x i8] c"3490\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [15 x i8] c"client: socket\00"
@.str.4 = [16 x i8] c"client: connect\00"
@.str.5 = [27 x i8] c"client: failed to connect\0A\00"
@.str.6 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.7 = [52 x i8] c"/home/kawaguchi/system-c/week4/record/client/record\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.10 = [5 x i8] c"dup2\00"
@.str.11 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [16 x i8]
%6 = alloca [2 x i32]
%7 = bitcast %struct.addrinfo* %3 to i8*
%8 = bitcast %struct.addrinfo** %4 to i8*
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = icmp eq i32 %0, 2
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%20 = load i32, i32* @AF_UNSPEC
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @SOCK_STREAM
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load %struct.addrinfo*, %struct.addrinfo** %4
%30 = icmp eq %struct.addrinfo* %29, null
br i1 %30, label %60, label %35
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = call i8* @gai_strerror(i32 %26)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %139
35: ; preds = %28, %54
%36 = phi %struct.addrinfo* [ %58, %54 ], [ %29, %28 ]
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 4
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 3
%42 = load i32, i32* %41
%43 = call i32 @socket(i32 %38, i32 %40, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %54, label %45
45: ; preds = %35
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 0
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 2
%49 = load i32, i32* %48
%50 = call i32 @connect(i32 %43, i64 %47, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %63
52: ; preds = %45
%53 = call i32 @close(i32 %43)
br label %54
54: ; preds = %35, %52
%55 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), %52 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %35 ]
%56 = call i32 @perror(i8* %55)
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 5
%58 = load %struct.addrinfo*, %struct.addrinfo** %57
%59 = icmp eq %struct.addrinfo* %58, null
br i1 %59, label %60, label %35
60: ; preds = %54, %28
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %139
63: ; preds = %45
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 1
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 0
%66 = load i32, i32* %64
%67 = load i64, i64* %65
%68 = inttoptr i64 %67 to %struct.sockaddr*
%69 = call i32 @get_in_addr(%struct.sockaddr* %68)
%70 = call i32 @inet_ntop(i32 %66, i32 %69, i8* %12, i32 %9)
%71 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%72 = load %struct.addrinfo*, %struct.addrinfo** %4
%73 = call i32 @freeaddrinfo(%struct.addrinfo* %72)
%74 = call i64 @malloc(i32 32)
%75 = inttoptr i64 %74 to i8**
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%77 = call i64 @malloc(i32 128)
%78 = inttoptr i64 %77 to i8*
store i8* %78, i8** %75
%79 = call i64 @malloc(i32 128)
%80 = inttoptr i64 %79 to i8*
%81 = getelementptr inbounds i8*, i8** %75, i64 1
store i8* %80, i8** %81
%82 = call i64 @malloc(i32 128)
%83 = inttoptr i64 %82 to i8*
%84 = getelementptr inbounds i8*, i8** %75, i64 2
store i8* %83, i8** %84
%85 = call i64 @malloc(i32 128)
%86 = inttoptr i64 %85 to i8*
%87 = getelementptr inbounds i8*, i8** %75, i64 3
store i8* %86, i8** %87
%88 = load i8*, i8** %75
%89 = call i32 @strcpy(i8* %88, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%90 = load i8*, i8** %81
%91 = call i32 @strcpy(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* null, i8** %84
%92 = bitcast [2 x i32]* %6 to i8*
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%94 = call i64 @pipe(i32* %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %101, label %96
96: ; preds = %63
%97 = call i32 @close(i32 %43)
%98 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %63
%102 = call i32 (...) @fork()
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %124
104: ; preds = %101
%105 = load i32, i32* %93
%106 = call i32 @close(i32 %105)
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%108 = load i32, i32* %107
%109 = load i32, i32* @STDOUT_FILENO
%110 = call i32 @dup2(i32 %108, i32 %109)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %118
112: ; preds = %104
%113 = load i32, i32* %107
%114 = call i32 @close(i32 %113)
%115 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%116 = load i32, i32* @EXIT_FAILURE
%117 = call i32 @exit(i32 %116)
unreachable
118: ; preds = %104
%119 = load i8*, i8** %75
%120 = call i32 @execvp(i8* %119, i8** %75)
%121 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %101
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%126 = load i32, i32* %125
%127 = call i32 @close(i32 %126)
%128 = load i32, i32* %93
%129 = call i64 @read(i32 %128, i8* %76, i32 16)
%130 = icmp sgt i64 %129, 0
br i1 %130, label %131, label %136
131: ; preds = %124, %131
%132 = call i32 @send(i32 %43, i8* %76, i32 16, i32 0)
%133 = load i32, i32* %93
%134 = call i64 @read(i32 %133, i8* %76, i32 16)
%135 = icmp sgt i64 %134, 0
br i1 %135, label %131, label %136
136: ; preds = %131, %124
%137 = call i32 @close(i32 %43)
%138 = call i32 @close(i32 %43)
br label %139
139: ; preds = %136, %60, %31
%140 = phi i32 [ 1, %31 ], [ 2, %60 ], [ 0, %136 ]
ret i32 %140
}