#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;
  *ename = (char *)malloc((128 * 4) * sizeof(char));
  while (i < 4) {
    *(ename + i) = *ename + (128 * i);
    ++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    16bf <main+0x46f>
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    16bf <main+0x46f>
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)
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,%rcx
mov    -0xd8(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x4,-0xcc(%rbp)
jge    1542 <main+0x2f2>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rdx
mov    -0xcc(%rbp),%eax
shl    $0x7,%eax
cltq
add    %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    14f7 <main+0x2a7>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rdi
lea    0xb2f(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0xd8(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb4c(%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     15b6 <main+0x366>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xb15(%rip),%rdi
call   1100 <perror@plt>
mov    0x2a09(%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    164d <main+0x3fd>
mov    -0xfc(%rbp),%edi
call   10b0 <close@plt>
mov    -0xf8(%rbp),%edi
mov    0x2a08(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0xffffffff,%eax
jne    161d <main+0x3cd>
mov    -0xf8(%rbp),%edi
call   10b0 <close@plt>
lea    0xab3(%rip),%rdi
call   1100 <perror@plt>
mov    0x29a2(%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    0xa88(%rip),%rdi
call   1100 <perror@plt>
mov    0x2972(%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    169e <main+0x44e>
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1662 <main+0x412>
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    0xd67(%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    0xd45(%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    0xd2c(%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    0xcfc(%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    0xcee(%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    0xcd1(%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    $0x200,%edi
call   10f0 <malloc@plt>
movq   %rax,%xmm0
pshufd $0x44,%xmm0,%xmm0
paddq  0xc1f(%rip),%xmm0
mov    %rax,(%r14)
movdqu %xmm0,0x8(%r14)
lea    0x180(%rax),%rcx
mov    %rcx,0x18(%r14)
lea    0xc96(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
mov    0x8(%r14),%rdi
lea    0xcb7(%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
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    0xb45(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
lea    0xbdd(%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    0xbb3(%rip),%rdi
jmp    152e <main+0x2de>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1110 <execvp@plt>
lea    0xba4(%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 %194
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 %194
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
%107 = call i64 @malloc(i32 512)
%108 = inttoptr i64 %107 to i8*
%109 = load i8**, i8*** %17
store i8* %108, i8** %109
br label %110
110: ; preds = %113, %91
%111 = load i32, i32* %15
%112 = icmp slt i32 %111, 4
br i1 %112, label %113, label %126
113: ; preds = %110
%114 = load i8**, i8*** %17
%115 = load i8*, i8** %114
%116 = load i32, i32* %15
%117 = mul nsw i32 128, %116
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %115, i64 %118
%120 = load i8**, i8*** %17
%121 = load i32, i32* %15
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8*, i8** %120, i64 %122
store i8* %119, i8** %123
%124 = load i32, i32* %15
%125 = add nsw i32 %124, 1
store i32 %125, i32* %15
br label %110
126: ; preds = %110
%127 = load i8**, i8*** %17
%128 = getelementptr inbounds i8*, i8** %127, i64 0
%129 = load i8*, i8** %128
%130 = call i32 @strcpy(i8* %129, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%131 = load i8**, i8*** %17
%132 = getelementptr inbounds i8*, i8** %131, i64 1
%133 = load i8*, i8** %132
%134 = call i32 @strcpy(i8* %133, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%135 = load i8**, i8*** %17
%136 = getelementptr inbounds i8*, i8** %135, i64 2
store i8* null, i8** %136
%137 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%138 = call i64 @pipe(i32* %137)
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %146
140: ; preds = %126
%141 = load i32, i32* %6
%142 = call i32 @close(i32 %141)
%143 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%144 = load i32, i32* @EXIT_FAILURE
%145 = call i32 @exit(i32 %144)
unreachable
146: ; preds = %126
%147 = call i32 (...) @fork()
store i32 %147, i32* %19
%148 = load i32, i32* %19
%149 = icmp ne i32 %148, 0
br i1 %149, label %174, label %150
150: ; preds = %146
%151 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%152 = load i32, i32* %151
%153 = call i32 @close(i32 %152)
%154 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%155 = load i32, i32* %154
%156 = load i32, i32* @STDOUT_FILENO
%157 = call i32 @dup2(i32 %155, i32 %156)
%158 = icmp eq i32 %157, -1
br i1 %158, label %159, label %166
159: ; preds = %150
%160 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%161 = load i32, i32* %160
%162 = call i32 @close(i32 %161)
%163 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%164 = load i32, i32* @EXIT_FAILURE
%165 = call i32 @exit(i32 %164)
unreachable
166: ; preds = %150
%167 = load i8**, i8*** %17
%168 = load i8*, i8** %167
%169 = load i8**, i8*** %17
%170 = call i32 @execvp(i8* %168, i8** %169)
%171 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%172 = load i32, i32* @EXIT_FAILURE
%173 = call i32 @exit(i32 %172)
unreachable
174: ; preds = %146
%175 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 1
%176 = load i32, i32* %175
%177 = call i32 @close(i32 %176)
store i32 0, i32* %15
br label %178
178: ; preds = %184, %174
%179 = getelementptr inbounds [2 x i32], [2 x i32]* %20, i64 0, i64 0
%180 = load i32, i32* %179
%181 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%182 = call i64 @read(i32 %180, i8* %181, i32 16)
%183 = icmp sgt i64 %182, 0
br i1 %183, label %184, label %188
184: ; preds = %178
%185 = load i32, i32* %6
%186 = getelementptr inbounds [16 x i8], [16 x i8]* %18, i64 0, i64 0
%187 = call i32 @send(i32 %185, i8* %186, i32 16, i32 0)
br label %178
188: ; preds = %178
%189 = load i32, i32* %6
%190 = call i32 @close(i32 %189)
br label %191
191: ; preds = %188
%192 = load i32, i32* %6
%193 = call i32 @close(i32 %192)
store i32 0, i32* %3
store i32 1, i32* %16
br label %194
194: ; preds = %191, %88, %42
%195 = load i8*, i8** %13
%196 = load i32, i32* %3
ret i32 %196
}

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 %137
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 %137
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 512)
%78 = inttoptr i64 %77 to i8*
store i8* %78, i8** %75
%79 = getelementptr inbounds i8*, i8** %75, i64 1
%80 = insertelement <2 x i8*> poison, i8* %78, i64 0
%81 = shufflevector <2 x i8*> %80, <2 x i8*> poison, <2 x i32> zeroinitializer
%82 = getelementptr i8, <2 x i8*> %81, <2 x i64> <i64 128, i64 256>
%83 = getelementptr inbounds i8*, i8** %75, i64 2
%84 = bitcast i8** %79 to <2 x i8*>*
store <2 x i8*> %82, <2 x i8*>* %84
%85 = getelementptr inbounds i8, i8* %78, i64 384
%86 = getelementptr inbounds i8*, i8** %75, i64 3
store i8* %85, i8** %86
%87 = call i32 @strcpy(i8* %78, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%88 = load i8*, i8** %79
%89 = call i32 @strcpy(i8* %88, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* null, i8** %83
%90 = bitcast [2 x i32]* %6 to i8*
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%92 = call i64 @pipe(i32* %91)
%93 = icmp eq i64 %92, 0
br i1 %93, label %99, label %94
94: ; preds = %63
%95 = call i32 @close(i32 %43)
%96 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %63
%100 = call i32 (...) @fork()
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %122
102: ; preds = %99
%103 = load i32, i32* %91
%104 = call i32 @close(i32 %103)
%105 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%106 = load i32, i32* %105
%107 = load i32, i32* @STDOUT_FILENO
%108 = call i32 @dup2(i32 %106, i32 %107)
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %116
110: ; preds = %102
%111 = load i32, i32* %105
%112 = call i32 @close(i32 %111)
%113 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %102
%117 = load i8*, i8** %75
%118 = call i32 @execvp(i8* %117, i8** %75)
%119 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %99
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%124 = load i32, i32* %123
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* %91
%127 = call i64 @read(i32 %126, i8* %76, i32 16)
%128 = icmp sgt i64 %127, 0
br i1 %128, label %129, label %134
129: ; preds = %122, %129
%130 = call i32 @send(i32 %43, i8* %76, i32 16, i32 0)
%131 = load i32, i32* %91
%132 = call i64 @read(i32 %131, i8* %76, i32 16)
%133 = icmp sgt i64 %132, 0
br i1 %133, label %129, label %134
134: ; preds = %129, %122
%135 = call i32 @close(i32 %43)
%136 = call i32 @close(i32 %43)
br label %137
137: ; preds = %134, %60, %31
%138 = phi i32 [ 1, %31 ], [ 2, %60 ], [ 0, %134 ]
ret i32 %138
}