#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_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct servent {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ saddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SOCK_STREAM;
unsigned short atoi(char *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(unsigned short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned short *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(unsigned short *, char, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct sockaddr_in saddr;
  struct hostent *hp;
  struct servent *serv_ent;
  int slen, s, rfd;
  register int i;
  FILE *rf;
  unsigned short buf0[256], buf1[256], buf2[256], sector_request;
  if (argc == 1)
    sector_request = 500;
  else if (argc == 2)
    sector_request = atoi(argv[1]);
  else {
    fprintf(stderr, "syntax: %s <flash sector to read>\n");
    exit(0);
  }
  slen = sizeof(saddr);
  bzero(&saddr, slen);
  saddr.sin_family = AF_INET;
  if (!(hp = gethostbyname("65.202.3.110"))) {
    perror("Bad Hostname!");
    exit(-1);
  };
  bcopy(hp->h_addr, &saddr.sin_addr, hp->h_length);
  saddr.sin_port = htons(5666);
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Bad Socket!");
    exit(-1);
  };
  memset(buf0, ' ', 256 * sizeof(unsigned short));
  memset(buf1, ' ', 256 * sizeof(unsigned short));
  memset(buf2, ' ', 256 * sizeof(unsigned short));
  while (connect(s, (struct sockaddr *)&saddr, slen))
    ;
  fprintf(stderr, "Connected\n");
  if (!(rf = fdopen(s, "r+"))) {
    perror("Bad fdopen!");
    exit(-1);
  };
  fprintf(stderr, "opened...");
  fwrite(&sector_request, sizeof(unsigned short), 1, rf);
  fseek(rf, 0, SEEK_CUR);
  fread(buf0, 128, 1, rf);
  fprintf(stderr, "read buffer 0...");
  fread(buf0 + 128 / 2, 128, 1, rf);
  fprintf(stderr, "read buffer 0a...");
  fread(buf0 + 128, 128, 1, rf);
  fprintf(stderr, "read buffer 0b...");
  fread(buf0 + 3 * 128 / 2, 128, 1, rf);
  fprintf(stderr, "read buffer 1...");
  fread(buf1, 128, 1, rf);
  fread(buf1 + 128 / 2, 128, 1, rf);
  fread(buf1 + 128, 128, 1, rf);
  fread(buf1 + 3 * 128 / 2, 128, 1, rf);
  fprintf(stderr, "read buffer 2...");
  fread(buf2, 128, 1, rf);
  fread(buf2 + 128 / 2, 128, 1, rf);
  fread(buf2 + 128, 128, 1, rf);
  fread(buf2 + 3 * 128 / 2, 128, 1, rf);
  fprintf(stderr, "read buffer 3\n");
  fclose(rf);
  for (i = 0; i < 256; i++)
    fprintf(stderr, "[%4d] %d %d %d\n", i, *(buf0 + i), *(buf1 + i),
            *(buf2 + i));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1231 <main+0x31>
movw   $0x1f4,-0x652(%rbp)
f4 01
jmp    1277 <main+0x77>
cmpl   $0x2,-0x8(%rbp)
jne    1254 <main+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %ax,-0x652(%rbp)
jmp    1272 <main+0x72>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    1277 <main+0x77>
movl   $0xc,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   10d0 <bzero@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xd86(%rip),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12c6 <main+0xc6>
lea    0xd79(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    $0x1622,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    1328 <main+0x128>
lea    0xd25(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    -0x250(%rbp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x450(%rbp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    -0x650(%rbp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1100 <connect@plt>
cmp    $0x0,%rax
je     1388 <main+0x188>
jmp    136a <main+0x16a>
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
lea    0xcb2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%edi
lea    0xcac(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13d2 <main+0x1d2>
lea    0xc95(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rcx
lea    -0x652(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x48(%rbp),%rdi
mov    0x2bd2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
lea    -0x250(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
lea    0xc2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x250(%rbp),%rdi
add    $0x80,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x250(%rbp),%rdi
add    $0x100,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    0xbe0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x250(%rbp),%rdi
add    $0x180,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2af0(%rip),%rax
mov    (%rax),%edi
lea    0xbba(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x450(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x450(%rbp),%rdi
add    $0x80,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x450(%rbp),%rdi
add    $0x100,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x450(%rbp),%rdi
add    $0x180,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2a5c(%rip),%rax
mov    (%rax),%edi
lea    0xb37(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x650(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x650(%rbp),%rdi
add    $0x80,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x650(%rbp),%rdi
add    $0x100,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x650(%rbp),%rdi
add    $0x180,%rdi
mov    -0x48(%rbp),%rcx
mov    $0x80,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x29c8(%rip),%rax
mov    (%rax),%edi
lea    0xab4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x40(%rbp)
cmpl   $0x100,-0x40(%rbp)
jge    1683 <main+0x483>
mov    0x2994(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%edx
movslq -0x40(%rbp),%rax
movzwl -0x250(%rbp,%rax,2),%ecx
ff
movslq -0x40(%rbp),%rax
movzwl -0x450(%rbp,%rax,2),%r8d
ff ff
movslq -0x40(%rbp),%rax
movzwl -0x650(%rbp,%rax,2),%r9d
ff ff
lea    0xa66(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1628 <main+0x428>
mov    -0x4(%rbp),%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x628,%rsp
mov    $0x1f4,%ax
cmp    $0x1,%edi
je     1228 <main+0x28>
cmp    $0x2,%edi
jne    157b <main+0x37b>
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %ax,0xe(%rsp)
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2da5(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xdd3(%rip),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1553 <main+0x353>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x14(%rsp),%rsi
call   10b0 <bcopy@plt>
mov    $0x1622,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     155c <main+0x35c>
mov    %eax,%ebp
lea    0x420(%rsp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    0x220(%rsp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    0x20(%rsp),%rdi
mov    $0x20,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rbx
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1100 <connect@plt>
test   %rax,%rax
jne    12e0 <main+0xe0>
mov    0x2cd5(%rip),%r15
mov    (%r15),%edi
lea    0xd45(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd42(%rip),%rsi
mov    %ebp,%edi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     1565 <main+0x365>
mov    %rax,%rbx
mov    (%r15),%edi
lea    0xd34(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1110 <fwrite@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x420(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xce9(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x4a0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xccf(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x520(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xcb6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x5a0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xc9d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x220(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x2a0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x320(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x3a0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xc35(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x20(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xa0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x120(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0x1a0(%rsp),%rdi
mov    $0x80,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    (%r15),%edi
lea    0xbd0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xbc9(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15),%edi
movzwl 0x420(%rsp,%rbx,2),%ecx
movzwl 0x220(%rsp,%rbx,2),%r8d
movzwl 0x20(%rsp,%rbx,2),%r9d
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1510 <main+0x310>
xor    %eax,%eax
add    $0x628,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xad6(%rip),%rdi
jmp    156c <main+0x36c>
lea    0xadb(%rip),%rdi
jmp    156c <main+0x36c>
lea    0xaec(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2a4e(%rip),%rax
mov    (%rax),%edi
lea    0xa75(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.servent = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"syntax: %s <flash sector to read>\0A\00"
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"65.202.3.110\00"
@.str.2 = [14 x i8] c"Bad Hostname!\00"
@SOCK_STREAM = global i32 0
@.str.3 = [12 x i8] c"Bad Socket!\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [12 x i8] c"Bad fdopen!\00"
@.str.7 = [10 x i8] c"opened...\00"
@SEEK_CUR = global i32 0
@.str.8 = [17 x i8] c"read buffer 0...\00"
@.str.9 = [18 x i8] c"read buffer 0a...\00"
@.str.10 = [18 x i8] c"read buffer 0b...\00"
@.str.11 = [17 x i8] c"read buffer 1...\00"
@.str.12 = [17 x i8] c"read buffer 2...\00"
@.str.13 = [15 x i8] c"read buffer 3\0A\00"
@.str.14 = [16 x i8] c"[%4d] %d %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca %struct.servent*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [256 x i16]
%15 = alloca [256 x i16]
%16 = alloca [256 x i16]
%17 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %2
store i16 500, i16* %17
br label %34
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call zeroext i16 @atoi(i8* %27)
store i16 %28, i16* %17
br label %33
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %24
br label %34
34: ; preds = %33, %20
store i32 12, i32* %9
%35 = load i32, i32* %9
%36 = call i32 @bzero(%struct.sockaddr_in* %6, i32 %35)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %37, i32* %38
%39 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store %struct.hostent* %39, %struct.hostent** %7
%40 = icmp ne %struct.hostent* %39, null
br i1 %40, label %44, label %41
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %34
%45 = load %struct.hostent*, %struct.hostent** %7
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%49 = load %struct.hostent*, %struct.hostent** %7
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @bcopy(i32 %47, i32* %48, i32 %51)
%53 = call i32 @htons(i32 5666)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* @AF_INET
%56 = load i32, i32* @SOCK_STREAM
%57 = call i32 @socket(i32 %55, i32 %56, i32 0)
store i32 %57, i32* %10
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %44
%60 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %44
%63 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%64 = call i32 @memset(i16* %63, i8 signext 32, i32 512)
%65 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%66 = call i32 @memset(i16* %65, i8 signext 32, i32 512)
%67 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%68 = call i32 @memset(i16* %67, i8 signext 32, i32 512)
br label %69
69: ; preds = %75, %62
%70 = load i32, i32* %10
%71 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%72 = load i32, i32* %9
%73 = call i64 @connect(i32 %70, %struct.sockaddr* %71, i32 %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %69
br label %69
76: ; preds = %69
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%79 = load i32, i32* %10
%80 = call i32* @fdopen(i32 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %80, i32** %13
%81 = icmp ne i32* %80, null
br i1 %81, label %85, label %82
82: ; preds = %76
%83 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %76
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%88 = load i32*, i32** %13
%89 = call i32 @fwrite(i16* %17, i32 2, i32 1, i32* %88)
%90 = load i32*, i32** %13
%91 = load i32, i32* @SEEK_CUR
%92 = call i32 @fseek(i32* %90, i32 0, i32 %91)
%93 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%94 = load i32*, i32** %13
%95 = call i32 @fread(i16* %93, i32 128, i32 1, i32* %94)
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%98 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%99 = getelementptr inbounds i16, i16* %98, i64 64
%100 = load i32*, i32** %13
%101 = call i32 @fread(i16* %99, i32 128, i32 1, i32* %100)
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%104 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%105 = getelementptr inbounds i16, i16* %104, i64 128
%106 = load i32*, i32** %13
%107 = call i32 @fread(i16* %105, i32 128, i32 1, i32* %106)
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%110 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%111 = getelementptr inbounds i16, i16* %110, i64 192
%112 = load i32*, i32** %13
%113 = call i32 @fread(i16* %111, i32 128, i32 1, i32* %112)
%114 = load i32, i32* @stderr
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%116 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%117 = load i32*, i32** %13
%118 = call i32 @fread(i16* %116, i32 128, i32 1, i32* %117)
%119 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%120 = getelementptr inbounds i16, i16* %119, i64 64
%121 = load i32*, i32** %13
%122 = call i32 @fread(i16* %120, i32 128, i32 1, i32* %121)
%123 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%124 = getelementptr inbounds i16, i16* %123, i64 128
%125 = load i32*, i32** %13
%126 = call i32 @fread(i16* %124, i32 128, i32 1, i32* %125)
%127 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%128 = getelementptr inbounds i16, i16* %127, i64 192
%129 = load i32*, i32** %13
%130 = call i32 @fread(i16* %128, i32 128, i32 1, i32* %129)
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
%133 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%134 = load i32*, i32** %13
%135 = call i32 @fread(i16* %133, i32 128, i32 1, i32* %134)
%136 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%137 = getelementptr inbounds i16, i16* %136, i64 64
%138 = load i32*, i32** %13
%139 = call i32 @fread(i16* %137, i32 128, i32 1, i32* %138)
%140 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%141 = getelementptr inbounds i16, i16* %140, i64 128
%142 = load i32*, i32** %13
%143 = call i32 @fread(i16* %141, i32 128, i32 1, i32* %142)
%144 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%145 = getelementptr inbounds i16, i16* %144, i64 192
%146 = load i32*, i32** %13
%147 = call i32 @fread(i16* %145, i32 128, i32 1, i32* %146)
%148 = load i32, i32* @stderr
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%150 = load i32*, i32** %13
%151 = call i32 @fclose(i32* %150)
store i32 0, i32* %12
br label %152
152: ; preds = %177, %85
%153 = load i32, i32* %12
%154 = icmp slt i32 %153, 256
br i1 %154, label %155, label %180
155: ; preds = %152
%156 = load i32, i32* @stderr
%157 = load i32, i32* %12
%158 = getelementptr inbounds [256 x i16], [256 x i16]* %14, i64 0, i64 0
%159 = load i32, i32* %12
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i16, i16* %158, i64 %160
%162 = load i16, i16* %161
%163 = zext i16 %162 to i32
%164 = getelementptr inbounds [256 x i16], [256 x i16]* %15, i64 0, i64 0
%165 = load i32, i32* %12
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i16, i16* %164, i64 %166
%168 = load i16, i16* %167
%169 = zext i16 %168 to i32
%170 = getelementptr inbounds [256 x i16], [256 x i16]* %16, i64 0, i64 0
%171 = load i32, i32* %12
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i16, i16* %170, i64 %172
%174 = load i16, i16* %173
%175 = zext i16 %174 to i32
%176 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0), i32 %157, i32 %163, i32 %169, i32 %175)
br label %177
177: ; preds = %155
%178 = load i32, i32* %12
%179 = add nsw i32 %178, 1
store i32 %179, i32* %12
br label %152
180: ; preds = %152
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.servent = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"syntax: %s <flash sector to read>\0A\00"
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"65.202.3.110\00"
@.str.2 = [14 x i8] c"Bad Hostname!\00"
@SOCK_STREAM = global i32 0
@.str.3 = [12 x i8] c"Bad Socket!\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [12 x i8] c"Bad fdopen!\00"
@.str.7 = [10 x i8] c"opened...\00"
@SEEK_CUR = global i32 0
@.str.8 = [17 x i8] c"read buffer 0...\00"
@.str.9 = [18 x i8] c"read buffer 0a...\00"
@.str.10 = [18 x i8] c"read buffer 0b...\00"
@.str.11 = [17 x i8] c"read buffer 1...\00"
@.str.12 = [17 x i8] c"read buffer 2...\00"
@.str.13 = [15 x i8] c"read buffer 3\0A\00"
@.str.14 = [16 x i8] c"[%4d] %d %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i16]
%5 = alloca [256 x i16]
%6 = alloca [256 x i16]
%7 = alloca i16
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast [256 x i16]* %4 to i8*
%10 = bitcast [256 x i16]* %5 to i8*
%11 = bitcast [256 x i16]* %6 to i8*
%12 = bitcast i16* %7 to i8*
switch i32 %0, label %17 [
i32 1, label %21
i32 2, label %13
]
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call zeroext i16 @atoi(i8* %15)
br label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %2, %13
%22 = phi i16 [ %16, %13 ], [ 500, %2 ]
store i16 %22, i16* %7
%23 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq %struct.hostent* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %21
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i64 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @bcopy(i32 %33, i32* %34, i32 %36)
%38 = call i32 @htons(i32 5666)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* @AF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = call i32 @socket(i32 %40, i32 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %31
%45 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %31
%48 = getelementptr inbounds [256 x i16], [256 x i16]* %4, i64 0, i64 0
%49 = call i32 @memset(i16* %48, i8 signext 32, i32 512)
%50 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 0
%51 = call i32 @memset(i16* %50, i8 signext 32, i32 512)
%52 = getelementptr inbounds [256 x i16], [256 x i16]* %6, i64 0, i64 0
%53 = call i32 @memset(i16* %52, i8 signext 32, i32 512)
%54 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %55
55: ; preds = %55, %47
%56 = call i64 @connect(i32 %42, %struct.sockaddr* %54, i32 12)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %55
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32* @fdopen(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %58
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%69 = call i32 @fwrite(i16* %7, i32 2, i32 1, i32* %61)
%70 = load i32, i32* @SEEK_CUR
%71 = call i32 @fseek(i32* %61, i32 0, i32 %70)
%72 = call i32 @fread(i16* %48, i32 128, i32 1, i32* %61)
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%75 = getelementptr inbounds [256 x i16], [256 x i16]* %4, i64 0, i64 64
%76 = call i32 @fread(i16* %75, i32 128, i32 1, i32* %61)
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%79 = getelementptr inbounds [256 x i16], [256 x i16]* %4, i64 0, i64 128
%80 = call i32 @fread(i16* %79, i32 128, i32 1, i32* %61)
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%83 = getelementptr inbounds [256 x i16], [256 x i16]* %4, i64 0, i64 192
%84 = call i32 @fread(i16* %83, i32 128, i32 1, i32* %61)
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%87 = call i32 @fread(i16* %50, i32 128, i32 1, i32* %61)
%88 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 64
%89 = call i32 @fread(i16* %88, i32 128, i32 1, i32* %61)
%90 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 128
%91 = call i32 @fread(i16* %90, i32 128, i32 1, i32* %61)
%92 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 192
%93 = call i32 @fread(i16* %92, i32 128, i32 1, i32* %61)
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
%96 = call i32 @fread(i16* %52, i32 128, i32 1, i32* %61)
%97 = getelementptr inbounds [256 x i16], [256 x i16]* %6, i64 0, i64 64
%98 = call i32 @fread(i16* %97, i32 128, i32 1, i32* %61)
%99 = getelementptr inbounds [256 x i16], [256 x i16]* %6, i64 0, i64 128
%100 = call i32 @fread(i16* %99, i32 128, i32 1, i32* %61)
%101 = getelementptr inbounds [256 x i16], [256 x i16]* %6, i64 0, i64 192
%102 = call i32 @fread(i16* %101, i32 128, i32 1, i32* %61)
%103 = load i32, i32* @stderr
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
%105 = call i32 @fclose(i32* %61)
br label %106
106: ; preds = %66, %106
%107 = phi i64 [ 0, %66 ], [ %120, %106 ]
%108 = load i32, i32* @stderr
%109 = getelementptr inbounds [256 x i16], [256 x i16]* %4, i64 0, i64 %107
%110 = load i16, i16* %109
%111 = zext i16 %110 to i32
%112 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 %107
%113 = load i16, i16* %112
%114 = zext i16 %113 to i32
%115 = getelementptr inbounds [256 x i16], [256 x i16]* %6, i64 0, i64 %107
%116 = load i16, i16* %115
%117 = zext i16 %116 to i32
%118 = trunc i64 %107 to i32
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0), i32 %118, i32 %111, i32 %114, i32 %117)
%120 = add nuw nsw i64 %107, 1
%121 = icmp eq i64 %120, 256
br i1 %121, label %122, label %106
122: ; preds = %106
ret i32 0
}