#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr_in *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getcwd(char *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, portno, n, i;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  char buffer[256];
  int length;
  if (argc < 2) {
    fprintf(stderr, "usage %s sourcename\n", argv[0]);
    exit(0);
  }
  portno = 12345;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  server = gethostbyname("localhost");
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(portno);
  if (connect(sockfd, &serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR connecting");
  getcwd(buffer, 255);
  strncat(buffer, "/\n", 2);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0)
    error("ERROR writing to socket");
  for (i = 1; i < argc; i++) {
    bzero(buffer, 256);
    strncat(buffer, argv[i], strlen(argv[i]));
    strncat(buffer, "\n", 1);
    n = write(sockfd, buffer, strlen(buffer));
    if (n < 0)
      error("ERROR writing to socket");
  }
  n = write(sockfd, "end\n", 4);
  if (n < 0)
    error("ERROR writing to socket");
  bzero(buffer, 256);
  length = 0;
  n = 1;
  while (n > 0 && length < 255 && (length == 0 || buffer[length - 1] != '\n')) {
    n = read(sockfd, &buffer[length], 255);
    length += n;
  }
  if (n < 0)
    error("ERROR reading from socket");
  close(sockfd);
  if (strncmp("ok\n", buffer, 3) == 0) {
    printf("ok: %s", buffer);
    return 0;
  } else if (strncmp("error", buffer, 5) == 0) {
    fprintf(stderr, "error: %s", buffer);
    return 1;
  } else {
    printf("unknown return code: %s\n", buffer);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1258 <main+0x48>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movl   $0x3039,-0x18(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1291 <main+0x81>
lea    0xd89(%rip),%rdi
call   10f0 <error@plt>
lea    0xd92(%rip),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12ca <main+0xba>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   10e0 <bcopy@plt>
mov    -0x18(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    1331 <main+0x121>
lea    0xd1d(%rip),%rdi
call   10f0 <error@plt>
lea    -0x140(%rbp),%rdi
mov    $0xff,%esi
call   1080 <getcwd@plt>
lea    -0x140(%rbp),%rdi
lea    0xd0a(%rip),%rsi
mov    $0x2,%edx
call   1090 <strncat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x154(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13aa <main+0x19a>
lea    0xcb8(%rip),%rdi
call   10f0 <error@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1490 <main+0x280>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1100 <bzero@plt>
lea    -0x140(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x170(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    -0x178(%rbp),%rdi
mov    -0x170(%rbp),%rsi
mov    %eax,%edx
call   1090 <strncat@plt>
lea    -0x140(%rbp),%rdi
lea    0xc38(%rip),%rsi
mov    $0x1,%edx
call   1090 <strncat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x164(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    147d <main+0x26d>
lea    0xbe5(%rip),%rdi
call   10f0 <error@plt>
jmp    1482 <main+0x272>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13b1 <main+0x1a1>
mov    -0x14(%rbp),%edi
lea    0xbdb(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14bd <main+0x2ad>
lea    0xba5(%rip),%rdi
call   10f0 <error@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1100 <bzero@plt>
movl   $0x0,-0x144(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x179(%rbp)
jle    1549 <main+0x339>
xor    %eax,%eax
cmpl   $0xff,-0x144(%rbp)
mov    %al,-0x179(%rbp)
jge    1549 <main+0x339>
mov    $0x1,%al
cmpl   $0x0,-0x144(%rbp)
mov    %al,-0x17a(%rbp)
je     153d <main+0x32d>
mov    -0x144(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x140(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
setne  %al
mov    %al,-0x17a(%rbp)
mov    -0x17a(%rbp),%al
mov    %al,-0x179(%rbp)
mov    -0x179(%rbp),%al
test   $0x1,%al
jne    155c <main+0x34c>
jmp    1591 <main+0x381>
mov    -0x14(%rbp),%edi
movslq -0x144(%rbp),%rax
lea    -0x140(%rbp),%rsi
add    %rax,%rsi
mov    $0xff,%edx
call   10b0 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x144(%rbp),%eax
mov    %eax,-0x144(%rbp)
jmp    14df <main+0x2cf>
cmpl   $0x0,-0x1c(%rbp)
jge    15a7 <main+0x397>
lea    0xad8(%rip),%rdi
call   10f0 <error@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
lea    -0x140(%rbp),%rsi
lea    0xad7(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    15f0 <main+0x3e0>
lea    -0x140(%rbp),%rsi
lea    0xab9(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1656 <main+0x446>
lea    -0x140(%rbp),%rsi
lea    0xaa1(%rip),%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    163c <main+0x42c>
mov    0x29bf(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rdx
lea    0xa7c(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1656 <main+0x446>
lea    -0x140(%rbp),%rsi
lea    0xa65(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,0x8(%rsp)
cmp    $0x1,%edi
jle    14a0 <main+0x290>
mov    %edi,%r15d
mov    0x2daf(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    125e <main+0x4e>
lea    0xdbc(%rip),%rdi
call   10f0 <error@plt>
lea    0xdc5(%rip),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     14c6 <main+0x2b6>
mov    %rax,%rbp
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rsi
lea    0x14(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10e0 <memmove@plt>
mov    $0x3039,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
jns    12ce <main+0xbe>
lea    0xd80(%rip),%rdi
call   10f0 <error@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xff,%esi
call   1080 <getcwd@plt>
lea    0xd73(%rip),%rsi
mov    %rbp,%rdi
mov    $0x2,%edx
call   1090 <strncat@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    1319 <main+0x109>
lea    0xd49(%rip),%rdi
call   10f0 <error@plt>
mov    %r15d,%r12d
mov    $0x1,%r14d
lea    0x20(%rsp),%rbp
lea    0xd2d(%rip),%r15
jmp    1339 <main+0x129>
add    $0x1,%r14
cmp    %r14,%r12
je     139b <main+0x18b>
mov    %rbp,%rdi
mov    $0x100,%esi
call   1100 <bzero@plt>
mov    0x8(%rsp),%rax
mov    (%rax,%r14,8),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1090 <strncat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1090 <strncat@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    1330 <main+0x120>
lea    0xcc9(%rip),%rdi
call   10f0 <error@plt>
jmp    1330 <main+0x120>
lea    0xcd3(%rip),%rsi
mov    %r13d,%edi
mov    $0x4,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    13bf <main+0x1af>
lea    0xca3(%rip),%rdi
call   10f0 <error@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
call   1100 <bzero@plt>
xor    %ebx,%ebx
xchg   %ax,%ax
movslq %ebx,%rax
test   %ebx,%ebx
je     13de <main+0x1ce>
cmpb   $0xa,-0x1(%rax,%rbp,1)
je     1411 <main+0x201>
lea    (%rsp,%rax,1),%rsi
add    $0x20,%rsi
mov    %r13d,%edi
mov    $0xff,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    1401 <main+0x1f1>
add    %eax,%ebx
cmp    $0xff,%ebx
jl     13d0 <main+0x1c0>
test   %eax,%eax
jns    1411 <main+0x201>
lea    0xc6e(%rip),%rdi
call   10f0 <error@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
lea    0xc74(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1458 <main+0x248>
lea    0xc64(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     146d <main+0x25d>
lea    0xc59(%rip),%rdi
jmp    145f <main+0x24f>
lea    0xc39(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1070 <printf@plt>
xor    %eax,%eax
jmp    148e <main+0x27e>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
lea    0xc28(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b31(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0xb48(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
lea    0xb5e(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"usage %s sourcename\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [3 x i8] c"/\0A\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [5 x i8] c"end\0A\00"
@.str.9 = [26 x i8] c"ERROR reading from socket\00"
@.str.10 = [4 x i8] c"ok\0A\00"
@.str.11 = [7 x i8] c"ok: %s\00"
@.str.12 = [6 x i8] c"error\00"
@.str.13 = [10 x i8] c"error: %s\00"
@.str.14 = [25 x i8] c"unknown return code: %s\0A\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 i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca [256 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
store i32 12345, i32* %7
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %32, %struct.hostent** %11
%33 = load %struct.hostent*, %struct.hostent** %11
%34 = icmp eq %struct.hostent* %33, null
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %31
%40 = bitcast %struct.sockaddr_in* %10 to i8*
%41 = call i32 @bzero(i8* %40, i32 12)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %42, i32* %43
%44 = load %struct.hostent*, %struct.hostent** %11
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i32 0, i32 1
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i8*
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
%50 = bitcast i32* %49 to i8*
%51 = load %struct.hostent*, %struct.hostent** %11
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @bcopy(i8* %47, i8* %50, i32 %53)
%55 = load i32, i32* %7
%56 = call i32 @htons(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %56, i32* %57
%58 = load i32, i32* %6
%59 = call i64 @connect(i32 %58, %struct.sockaddr_in* %10, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %39
%62 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %39
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%65 = call i32 @getcwd(i8* %64, i32 255)
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%67 = call i32 @strncat(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%68 = load i32, i32* %6
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @write(i32 %68, i8* %69, i32 %71)
store i32 %72, i32* %8
%73 = load i32, i32* %8
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %63
%76 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %77
77: ; preds = %75, %63
store i32 1, i32* %9
br label %78
78: ; preds = %110, %77
%79 = load i32, i32* %9
%80 = load i32, i32* %4
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %113
82: ; preds = %78
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%84 = call i32 @bzero(i8* %83, i32 256)
%85 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%86 = load i8**, i8*** %5
%87 = load i32, i32* %9
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8*, i8** %86, i64 %88
%90 = load i8*, i8** %89
%91 = load i8**, i8*** %5
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 @strlen(i8* %95)
%97 = call i32 @strncat(i8* %85, i8* %90, i32 %96)
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%99 = call i32 @strncat(i8* %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1)
%100 = load i32, i32* %6
%101 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%102 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%103 = call i32 @strlen(i8* %102)
%104 = call i32 @write(i32 %100, i8* %101, i32 %103)
store i32 %104, i32* %8
%105 = load i32, i32* %8
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %82
%108 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %109
109: ; preds = %107, %82
br label %110
110: ; preds = %109
%111 = load i32, i32* %9
%112 = add nsw i32 %111, 1
store i32 %112, i32* %9
br label %78
113: ; preds = %78
%114 = load i32, i32* %6
%115 = call i32 @write(i32 %114, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
store i32 %115, i32* %8
%116 = load i32, i32* %8
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %113
%119 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %120
120: ; preds = %118, %113
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%122 = call i32 @bzero(i8* %121, i32 256)
store i32 0, i32* %13
store i32 1, i32* %8
br label %123
123: ; preds = %144, %120
%124 = load i32, i32* %8
%125 = icmp sgt i32 %124, 0
br i1 %125, label %126, label %142
126: ; preds = %123
%127 = load i32, i32* %13
%128 = icmp slt i32 %127, 255
br i1 %128, label %129, label %142
129: ; preds = %126
%130 = load i32, i32* %13
%131 = icmp eq i32 %130, 0
br i1 %131, label %140, label %132
132: ; preds = %129
%133 = load i32, i32* %13
%134 = sub nsw i32 %133, 1
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %135
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = icmp ne i32 %138, 10
br label %140
140: ; preds = %132, %129
%141 = phi i1 [ true, %129 ], [ %139, %132 ]
br label %142
142: ; preds = %140, %126, %123
%143 = phi i1 [ false, %126 ], [ false, %123 ], [ %141, %140 ]
br i1 %143, label %144, label %153
144: ; preds = %142
%145 = load i32, i32* %6
%146 = load i32, i32* %13
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %147
%149 = call i32 @read(i32 %145, i8* %148, i32 255)
store i32 %149, i32* %8
%150 = load i32, i32* %8
%151 = load i32, i32* %13
%152 = add nsw i32 %151, %150
store i32 %152, i32* %13
br label %123
153: ; preds = %142
%154 = load i32, i32* %8
%155 = icmp slt i32 %154, 0
br i1 %155, label %156, label %158
156: ; preds = %153
%157 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %158
158: ; preds = %156, %153
%159 = load i32, i32* %6
%160 = call i32 @close(i32 %159)
%161 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%162 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %161, i32 3)
%163 = icmp eq i64 %162, 0
br i1 %163, label %164, label %167
164: ; preds = %158
%165 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%166 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %165)
store i32 0, i32* %3
br label %178
167: ; preds = %158
%168 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%169 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %168, i32 5)
%170 = icmp eq i64 %169, 0
br i1 %170, label %171, label %175
171: ; preds = %167
%172 = load i32, i32* @stderr
%173 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%174 = call i32 (i32, i8*, ...) @fprintf(i32 %172, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* %173)
store i32 1, i32* %3
br label %178
175: ; preds = %167
%176 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%177 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.14, i64 0, i64 0), i8* %176)
store i32 0, i32* %3
br label %178
178: ; preds = %175, %171, %164
%179 = load i32, i32* %3
ret i32 %179
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"usage %s sourcename\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [3 x i8] c"/\0A\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [5 x i8] c"end\0A\00"
@.str.9 = [26 x i8] c"ERROR reading from socket\00"
@.str.10 = [4 x i8] c"ok\0A\00"
@.str.11 = [7 x i8] c"ok: %s\00"
@.str.12 = [6 x i8] c"error\00"
@.str.13 = [10 x i8] c"error: %s\00"
@.str.14 = [25 x i8] c"unknown return code: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32 @exit(i32 0)
unreachable
27: ; preds = %20
%28 = call i32 @bzero(i8* %5, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%32 = load i64, i64* %31
%33 = inttoptr i64 %32 to i8*
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%35 = bitcast i32* %34 to i8*
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%37 = load i32, i32* %36
%38 = tail call i32 @htons(i32 12345)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %38, i32* %39
%40 = call i64 @connect(i32 %16, %struct.sockaddr_in* %3, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %27
%43 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %27
%45 = call i32 @getcwd(i8* %6, i32 255)
%46 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%47 = call i32 @strlen(i8* %6)
%48 = call i32 @write(i32 %16, i8* %6, i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %44, %50
%53 = zext i32 %0 to i64
br label %54
54: ; preds = %52, %67
%55 = phi i64 [ 1, %52 ], [ %68, %67 ]
%56 = call i32 @bzero(i8* %6, i32 256)
%57 = getelementptr inbounds i8*, i8** %1, i64 %55
%58 = load i8*, i8** %57
%59 = call i32 @strlen(i8* %58)
%60 = call i32 @strncat(i8* %6, i8* %58, i32 %59)
%61 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1)
%62 = call i32 @strlen(i8* %6)
%63 = call i32 @write(i32 %16, i8* %6, i32 %62)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %54
%66 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %54, %65
%68 = add nuw nsw i64 %55, 1
%69 = icmp eq i64 %68, %53
br i1 %69, label %70, label %54
70: ; preds = %67
%71 = call i32 @write(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
%76 = call i32 @bzero(i8* %6, i32 256)
br label %77
77: ; preds = %75, %86
%78 = phi i32 [ 0, %75 ], [ %90, %86 ]
%79 = icmp eq i32 %78, 0
br i1 %79, label %86, label %80
80: ; preds = %77
%81 = add nsw i32 %78, -1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = icmp eq i8 %84, 10
br i1 %85, label %98, label %86
86: ; preds = %77, %80
%87 = sext i32 %78 to i64
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %87
%89 = call i32 @read(i32 %16, i8* %88, i32 255)
%90 = add nsw i32 %89, %78
%91 = icmp sgt i32 %89, 0
%92 = icmp slt i32 %90, 255
%93 = select i1 %91, i1 %92, i1 false
br i1 %93, label %77, label %94
94: ; preds = %86
%95 = icmp slt i32 %89, 0
br i1 %95, label %96, label %98
96: ; preds = %94
%97 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %98
98: ; preds = %80, %96, %94
%99 = call i32 @close(i32 %16)
%100 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %6, i32 3)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* %6)
br label %112
104: ; preds = %98
%105 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %6, i32 5)
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* %6)
br label %112
110: ; preds = %104
%111 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.14, i64 0, i64 0), i8* %6)
br label %112
112: ; preds = %110, %107, %102
%113 = phi i32 [ 0, %102 ], [ 1, %107 ], [ 0, %110 ]
ret i32 %113
}