#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 stat {
  int /*<<< orphan*/ st_mode;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int atoi(char *);
scalar_t__ atol(char *);
int close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fsize(int);
int fstat(int, struct stat *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *mmap(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int munmap(char *, scalar_t__);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  struct stat sb;
  off_t len, count;
  char *p;
  int fd;
  if (argc < 3) {
    fprintf(stderr, "usage: %s <file> <len>\n", argv[0]);
    return 1;
  }
  len = atol(argv[2]);
  portno = atoi(argv[4]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    error("Error creating socket");
    exit(1);
  }
  server = gethostbyname(argv[3]);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  memcpy((char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr,
         server->h_length);
  serv_addr.sin_port = htons(portno);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    error("ERROR connecting");
  }
  if (len <= 0) {
    perror("len should be interger number of bytes");
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  if (fstat(fd, &sb) == -1) {
    perror("fstat");
    return 1;
  }
  if (!S_ISREG(sb.st_mode) && !S_ISCHR(sb.st_mode)) {
    fprintf(stderr, "%s is not a regular or a character file\n", argv[1]);
    return 1;
  }
  p = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
  if (p == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  count = fsize(fd);
  fprintf(stderr, "count: %ld\n", count);
  n = write(sockfd, p, count);
  if (n < 0) {
    fprintf(stderr, "ERROR, write, %s\n", strerror(errno));
    exit(1);
  }
  close(sockfd);
  if (close(fd) == -1) {
    perror("close");
    return 1;
  }
  if (munmap(p, len) == -1) {
    perror("munmap");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    12aa <main+0x4a>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1307 <main+0xa7>
lea    0xd20(%rip),%rdi
call   10e0 <error@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1341 <main+0xe1>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10a0 <memcpy@plt>
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
cmp    $0x0,%rax
jge    13aa <main+0x14a>
lea    0xc9e(%rip),%rdi
call   10e0 <error@plt>
cmpq   $0x0,-0x40(%rbp)
jg     13cd <main+0x16d>
lea    0xc98(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2bf4(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1408 <main+0x1a8>
lea    0xc84(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x54(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1170 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1435 <main+0x1d5>
lea    0xc5c(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x38(%rbp),%edi
call   10b0 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1482 <main+0x222>
mov    -0x38(%rbp),%edi
call   10c0 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    1482 <main+0x222>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x40(%rbp),%rsi
mov    0x2b6b(%rip),%rax
mov    (%rax),%edx
mov    0x2b52(%rip),%rax
mov    (%rax),%ecx
mov    -0x54(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    0x2af1(%rip),%rcx
cmp    (%rcx),%rax
jne    14d8 <main+0x278>
lea    0xbe8(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x54(%rbp),%edi
call   10f0 <fsize@plt>
mov    %rax,-0x48(%rbp)
mov    0x2ad5(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1554 <main+0x2f4>
mov    0x2a9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xb7d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x54(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1585 <main+0x325>
lea    0xb5e(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10d0 <munmap@plt>
cmp    $0xffffffff,%eax
jne    15b3 <main+0x353>
lea    0xb36(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ba <main+0x35a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1295 <main+0x35>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    148d <main+0x22d>
mov    0x10(%rbx),%rdi
call   1100 <atol@plt>
mov    %rax,%r15
mov    0x20(%rbx),%rdi
call   1130 <atoi@plt>
mov    %eax,%r12d
mov    0x2d24(%rip),%r14
mov    (%r14),%edi
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     14a1 <main+0x241>
mov    0x18(%rbx),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     14b7 <main+0x257>
mov    %rax,%rbp
lea    0x18(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x20(%rsp)
lea    0x1c(%rsp),%rdi
mov    0x8(%rbp),%rsi
mov    0x0(%rbp),%edx
call   10a0 <memcpy@plt>
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0xc(%rsp),%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
test   %rax,%rax
jns    1342 <main+0xe2>
lea    0xd06(%rip),%rdi
call   10e0 <error@plt>
test   %r15,%r15
jle    145d <main+0x1fd>
mov    %r15,%r13
mov    0x8(%rbx),%rdi
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     1466 <main+0x206>
mov    %eax,%r12d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1170 <fstat@plt>
cmp    $0xffffffff,%eax
je     146f <main+0x20f>
mov    0x10(%rsp),%ebp
mov    %ebp,%edi
call   10b0 <S_ISREG@plt>
test   %eax,%eax
jne    139f <main+0x13f>
mov    %ebp,%edi
call   10c0 <S_ISCHR@plt>
test   %eax,%eax
je     1444 <main+0x1e4>
mov    0x2c52(%rip),%rax
mov    (%rax),%edx
mov    0x2c39(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r13,%rsi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
mov    0x2bdd(%rip),%rax
cmp    (%rax),%r15
je     1478 <main+0x218>
mov    %r12d,%edi
call   10f0 <fsize@plt>
mov    %rax,%rbp
mov    0x2bda(%rip),%r14
mov    (%r14),%edi
lea    0xcc4(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
test   %eax,%eax
js     14d5 <main+0x275>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     1481 <main+0x221>
mov    %r15,%rdi
mov    %r13,%rsi
call   10d0 <munmap@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1492 <main+0x232>
lea    0xc96(%rip),%rdi
jmp    1488 <main+0x228>
mov    0x2b75(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xc2e(%rip),%rsi
jmp    1289 <main+0x29>
lea    0xbf0(%rip),%rdi
jmp    1488 <main+0x228>
lea    0xc0e(%rip),%rdi
jmp    1488 <main+0x228>
lea    0xc0a(%rip),%rdi
jmp    1488 <main+0x228>
lea    0xc30(%rip),%rdi
jmp    1488 <main+0x228>
lea    0xc4a(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb70(%rip),%rdi
call   10e0 <error@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
lea    0xb67(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    (%r14),%ebx
mov    0x2ad1(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xbd3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <file> <len>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Error creating socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [39 x i8] c"len should be interger number of bytes\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [6 x i8] c"fstat\00"
@.str.7 = [41 x i8] c"%s is not a regular or a character file\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [5 x i8] c"mmap\00"
@.str.9 = [12 x i8] c"count: %ld\0A\00"
@.str.10 = [18 x i8] c"ERROR, write, %s\0A\00"
@errno = global i32 0
@.str.11 = [6 x i8] c"close\00"
@.str.12 = [7 x i8] c"munmap\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 %struct.sockaddr_in
%10 = alloca %struct.hostent*
%11 = alloca %struct.stat
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %159
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @atol(i8* %27)
store i64 %28, i64* %12
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 4
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %7
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %24
%39 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %24
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call %struct.hostent* @gethostbyname(i8* %44)
store %struct.hostent* %45, %struct.hostent** %10
%46 = load %struct.hostent*, %struct.hostent** %10
%47 = icmp eq %struct.hostent* %46, null
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %41
%53 = bitcast %struct.sockaddr_in* %9 to i8*
%54 = call i32 @memset(i8* %53, i32 0, i32 12)
%55 = load i32, i32* @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %55, i32* %56
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
%59 = bitcast i32* %58 to i8*
%60 = load %struct.hostent*, %struct.hostent** %10
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %60, i32 0, i32 1
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to i8*
%64 = load %struct.hostent*, %struct.hostent** %10
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 @memcpy(i8* %59, i8* %63, i32 %66)
%68 = load i32, i32* %7
%69 = call i32 @htons(i32 %68)
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %69, i32* %70
%71 = load i32, i32* %6
%72 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%73 = call i64 @connect(i32 %71, %struct.sockaddr* %72, i32 12)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %52
%76 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %52
%78 = load i64, i64* %12
%79 = icmp sle i64 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %159
82: ; preds = %77
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = load i32, i32* @O_RDONLY
%87 = call i32 @open(i8* %85, i32 %86)
store i32 %87, i32* %15
%88 = load i32, i32* %15
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %82
%91 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %159
92: ; preds = %82
%93 = load i32, i32* %15
%94 = call i32 @fstat(i32 %93, %struct.stat* %11)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %159
98: ; preds = %92
%99 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%100 = load i32, i32* %99
%101 = call i32 @S_ISREG(i32 %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %114, label %103
103: ; preds = %98
%104 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%105 = load i32, i32* %104
%106 = call i32 @S_ISCHR(i32 %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %114, label %108
108: ; preds = %103
%109 = load i32, i32* @stderr
%110 = load i8**, i8*** %5
%111 = getelementptr inbounds i8*, i8** %110, i64 1
%112 = load i8*, i8** %111
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %112)
store i32 1, i32* %3
br label %159
114: ; preds = %103, %98
%115 = load i64, i64* %12
%116 = load i32, i32* @PROT_READ
%117 = load i32, i32* @MAP_SHARED
%118 = load i32, i32* %15
%119 = call i8* @mmap(i32* null, i64 %115, i32 %116, i32 %117, i32 %118, i32 0)
store i8* %119, i8** %14
%120 = load i8*, i8** %14
%121 = load i8*, i8** @MAP_FAILED
%122 = icmp eq i8* %120, %121
br i1 %122, label %123, label %125
123: ; preds = %114
%124 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %159
125: ; preds = %114
%126 = load i32, i32* %15
%127 = call i64 @fsize(i32 %126)
store i64 %127, i64* %13
%128 = load i32, i32* @stderr
%129 = load i64, i64* %13
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i64 %129)
%131 = load i32, i32* %6
%132 = load i8*, i8** %14
%133 = load i64, i64* %13
%134 = call i32 @write(i32 %131, i8* %132, i64 %133)
store i32 %134, i32* %8
%135 = load i32, i32* %8
%136 = icmp slt i32 %135, 0
br i1 %136, label %137, label %143
137: ; preds = %125
%138 = load i32, i32* @stderr
%139 = load i32, i32* @errno
%140 = call i8* @strerror(i32 %139)
%141 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %140)
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %125
%144 = load i32, i32* %6
%145 = call i32 @close(i32 %144)
%146 = load i32, i32* %15
%147 = call i32 @close(i32 %146)
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %151
149: ; preds = %143
%150 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %159
151: ; preds = %143
%152 = load i8*, i8** %14
%153 = load i64, i64* %12
%154 = call i32 @munmap(i8* %152, i64 %153)
%155 = icmp eq i32 %154, -1
br i1 %155, label %156, label %158
156: ; preds = %151
%157 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %159
158: ; preds = %151
store i32 0, i32* %3
br label %159
159: ; preds = %158, %156, %149, %123, %108, %96, %90, %80, %18
%160 = load i32, i32* %3
ret i32 %160
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <file> <len>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Error creating socket\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [39 x i8] c"len should be interger number of bytes\00"
@O_RDONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [6 x i8] c"fstat\00"
@.str.7 = [41 x i8] c"%s is not a regular or a character file\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [5 x i8] c"mmap\00"
@.str.9 = [12 x i8] c"count: %ld\0A\00"
@.str.10 = [18 x i8] c"ERROR, write, %s\0A\00"
@errno = global i32 0
@.str.11 = [6 x i8] c"close\00"
@.str.12 = [7 x i8] c"munmap\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.stat
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %12
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 ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %114
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @atol(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %12
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call %struct.hostent* @gethostbyname(i8* %28)
%30 = icmp eq %struct.hostent* %29, null
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 @exit(i32 0)
unreachable
35: ; preds = %26
%36 = call i32 @memset(i8* %5, i32 0, i32 12)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%40 = bitcast i32* %39 to i8*
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i64 0, i32 1
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to i8*
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @memcpy(i8* %40, i8* %43, i32 %45)
%47 = call i32 @htons(i32 %18)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %47, i32* %48
%49 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%50 = call i64 @connect(i32 %21, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %35
%53 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %35
%55 = icmp slt i64 %15, 1
br i1 %55, label %56, label %58
56: ; preds = %54
%57 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %114
58: ; preds = %54
%59 = getelementptr inbounds i8*, i8** %1, i64 1
%60 = load i8*, i8** %59
%61 = load i32, i32* @O_RDONLY
%62 = call i32 @open(i8* %60, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %114
66: ; preds = %58
%67 = call i32 @fstat(i32 %62, %struct.stat* %4)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %114
71: ; preds = %66
%72 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @S_ISREG(i32 %73)
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %71
%77 = call i32 @S_ISCHR(i32 %73)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %59
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %81)
br label %114
83: ; preds = %76, %71
%84 = load i32, i32* @PROT_READ
%85 = load i32, i32* @MAP_SHARED
%86 = call i8* @mmap(i32* null, i64 %15, i32 %84, i32 %85, i32 %62, i32 0)
%87 = load i8*, i8** @MAP_FAILED
%88 = icmp eq i8* %86, %87
br i1 %88, label %89, label %91
89: ; preds = %83
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %114
91: ; preds = %83
%92 = call i64 @fsize(i32 %62)
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i64 %92)
%95 = call i32 @write(i32 %21, i8* %86, i64 %92)
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %91
%98 = load i32, i32* @stderr
%99 = load i32, i32* @errno
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %100)
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %91
%104 = call i32 @close(i32 %21)
%105 = call i32 @close(i32 %62)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %114
109: ; preds = %103
%110 = call i32 @munmap(i8* %86, i64 %15)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %114
112: ; preds = %109
%113 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
br label %114
114: ; preds = %109, %112, %107, %89, %79, %69, %64, %56, %8
%115 = phi i32 [ 1, %8 ], [ 1, %56 ], [ 1, %64 ], [ 1, %69 ], [ 1, %89 ], [ 1, %107 ], [ 1, %112 ], [ 1, %79 ], [ 0, %109 ]
ret i32 %115
}