#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 */
typedef int uint32_t;
typedef char uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
char atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int htonl(int);
void *htons(char);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memcpy(char *, ...);
int /*<<< orphan*/ memset(struct sockaddr_in *, int, int);
int ntohl(int);
int open(char *, int, int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i, fd, loop, f;
  ssize_t n;
  uint16_t qtype, type = 0x0001;
  uint16_t rcode;
  uint32_t body_n;
  struct sockaddr_in sin;
  char send_buf[102406], recv_buf[1024];
  f = open("upload_list", O_CREAT | O_TRUNC | O_WRONLY, 0644);
  if (f == -1) {
    fprintf(stderr, "open() failed %s\n", strerror(errno));
    return -1;
  }
  loop = 1024;
  if (argc != 3 && argc != 4) {
    fprintf(stderr,
            "dfs_client_upload <ip> <port> [0|1, upload(default)|upload_sc]\n");
    fprintf(stderr, "dfs_client_upload 10.101.69.16 1304\n");
    return 1;
  }
  if (argc == 4) {
    if (atoi(argv[3]) == 1) {
      type = 0x0008;
    }
  }
  memset(&sin, 0x00, sizeof(struct sockaddr_in));
  sin.sin_family = AF_INET;
  sin.sin_port = htons(atoi(argv[2]));
  sin.sin_addr.s_addr = inet_addr(argv[1]);
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (fd == -1) {
    fprintf(stderr, "socket() failed: %s\n", strerror(errno));
    return 1;
  }
  if (connect(fd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in)) == -1) {
    fprintf(stderr, "connect(%s:%hu) failed: %s\n", argv[1], atoi(argv[2]),
            strerror(errno));
    return 1;
  }
  qtype = htons(type);
  rcode = 0;
  body_n = htonl((i + 1));
  memcpy(send_buf, &body_n, 4);
  memcpy(send_buf + 6, &qtype, 2);
  memcpy(send_buf + 8, "0123456789", 10);
  n = send(fd, send_buf, 8 + (i + 1), 0);
  if (n == -1) {
    fprintf(stderr, "send() failed: %s\n", strerror(errno));
    return 1;
  }
  fprintf(stderr, "send %ld\n", n);
  n = recv(fd, recv_buf, 1024, 0);
  if (n == -1) {
    fprintf(stderr, "recv() failed: %s\n", strerror(errno));
    return 1;
  }
  recv_buf[n] = '\0';
  body_n = ntohl(*((uint32_t *)recv_buf));
  fprintf(stderr, "recv %ld, body_n %u, fid %s\n", n, body_n, recv_buf + 8);
  recv_buf[n] = '\n';
  write(f, recv_buf + 8, body_n + 1);
  close(fd);
  close(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x19480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1,-0x26(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
or     (%rax),%esi
mov    0x2d72(%rip),%rax
or     (%rax),%esi
lea    0xdc1(%rip),%rdi
mov    $0x1a4,%edx
call   10d0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1296 <main+0x96>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x19454(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x19454(%rbp),%edi
mov    %rax,%rdx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    161e <main+0x41e>
movl   $0x400,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     12eb <main+0xeb>
cmpl   $0x4,-0x8(%rbp)
je     12eb <main+0xeb>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    161e <main+0x41e>
cmpl   $0x4,-0x8(%rbp)
jne    1317 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
movsbl %al,%eax
cmp    $0x1,%eax
jne    1312 <main+0x112>
movb   $0x8,-0x26(%rbp)
jmp    1317 <main+0x117>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
movsbl %al,%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x48(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
mov    0x2c54(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13c2 <main+0x1c2>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x19458(%rbp)
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x19458(%rbp),%edi
mov    %rax,%rdx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    161e <main+0x41e>
mov    -0x18(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x18,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    144e <main+0x24e>
mov    0x2be5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1946c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x19468(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
movsbl %al,%eax
mov    %eax,-0x1945c(%rbp)
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x1946c(%rbp),%edi
mov    -0x19468(%rbp),%rdx
mov    -0x1945c(%rbp),%ecx
mov    %rax,%r8
lea    0xc5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    161e <main+0x41e>
movsbl -0x26(%rbp),%edi
call   1050 <htons@plt>
mov    %al,-0x25(%rbp)
movb   $0x0,-0x27(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <htonl@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x19050(%rbp),%rdi
xor    %eax,%eax
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <memcpy@plt>
lea    -0x19050(%rbp),%rdi
add    $0x6,%rdi
xor    %eax,%eax
lea    -0x25(%rbp),%rsi
mov    $0x2,%edx
call   10c0 <memcpy@plt>
lea    -0x19050(%rbp),%rdi
add    $0x8,%rdi
lea    0xc04(%rip),%rsi
xor    %eax,%eax
mov    $0xa,%edx
call   10c0 <memcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0x19050(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
add    $0x8,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1523 <main+0x323>
mov    0x2ade(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x19470(%rbp)
mov    0x2abf(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x19470(%rbp),%edi
mov    %rax,%rdx
lea    0xbaf(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    161e <main+0x41e>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xb9c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x19450(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    15a0 <main+0x3a0>
mov    0x2a61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x19474(%rbp)
mov    0x2a42(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x19474(%rbp),%edi
mov    %rax,%rdx
lea    0xb4f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    161e <main+0x41e>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x19450(%rbp,%rax,1)
mov    -0x19450(%rbp),%edi
call   1100 <ntohl@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2a07(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    -0x19450(%rbp),%r8
add    $0x8,%r8
lea    0xb14(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movslq -0x24(%rbp),%rax
movb   $0xa,-0x19450(%rbp,%rax,1)
0a
mov    -0x20(%rbp),%edi
lea    -0x19450(%rbp),%rsi
add    $0x8,%rsi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x19480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x19428,%rsp
mov    0x2de0(%rip),%rcx
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2d79(%rip),%rcx
or     (%rcx),%eax
lea    0xdc8(%rip),%rdi
mov    %eax,%esi
mov    $0x1a4,%edx
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1280 <main+0x80>
mov    %eax,%r15d
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     12b4 <main+0xb4>
mov    0x2d6d(%rip),%rbx
mov    (%rbx),%edi
lea    0xdba(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdea(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1507 <main+0x307>
mov    0x2d41(%rip),%rax
mov    (%rax),%ebx
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xd6e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    150c <main+0x30c>
mov    $0x1,%r12b
cmp    $0x4,%ebx
jne    12d6 <main+0xd6>
mov    0x18(%rbp),%rdi
call   10e0 <atoi@plt>
cmp    $0x1,%al
mov    $0x8,%eax
mov    $0x1,%r12d
cmove  %eax,%r12d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2cea(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rbp),%rdi
call   10e0 <atoi@plt>
movsbl %al,%edi
call   1050 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%edi
mov    0x2ca0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     146a <main+0x26a>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
je     148a <main+0x28a>
movzbl %r12b,%edi
call   1050 <htons@plt>
mov    %al,0x3(%rsp)
call   1070 <htonl@plt>
mov    %eax,0x4(%rsp)
lea    0x420(%rsp),%rbp
lea    0x4(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <memcpy@plt>
lea    0x426(%rsp),%rdi
lea    0x3(%rsp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10c0 <memcpy@plt>
lea    0x428(%rsp),%rdi
lea    0xd0b(%rip),%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   10c0 <memcpy@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
mov    0x2bff(%rip),%r12
mov    (%r12),%ebx
cmp    $0xffffffff,%eax
je     14cb <main+0x2cb>
lea    0xcf5(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     14e2 <main+0x2e2>
mov    %eax,%ebx
movslq %eax,%r13
movb   $0x0,0x20(%rsp,%r13,1)
mov    0x20(%rsp),%edi
call   1100 <ntohl@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
lea    0x28(%rsp),%r12
lea    0xcc0(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
movb   $0xa,0x20(%rsp,%r13,1)
mov    0x4(%rsp),%edx
add    $0x1,%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1040 <write@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %r15d,%edi
call   1090 <close@plt>
jmp    150c <main+0x30c>
mov    0x2b57(%rip),%rax
mov    (%rax),%ebx
mov    0x2b3e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbfb(%rip),%rsi
jmp    14fb <main+0x2fb>
mov    0x2b37(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rbp),%r14
mov    0x10(%rbp),%rdi
call   10e0 <atoi@plt>
movsbl %al,%ebp
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbe0(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1507 <main+0x307>
mov    0x2ae6(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbdf(%rip),%rsi
jmp    14fb <main+0x2fb>
mov    (%r12),%ebx
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbe1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x19428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [12 x i8] c"upload_list\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"open() failed %s\0A\00"
@errno = global i32 0
@.str.2 = [64 x i8] c"dfs_client_upload <ip> <port> [0|1, upload(default)|upload_sc]\0A\00"
@.str.3 = [37 x i8] c"dfs_client_upload 10.101.69.16 1304\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [21 x i8] c"socket() failed: %s\0A\00"
@.str.5 = [28 x i8] c"connect(%s:%hu) failed: %s\0A\00"
@.str.6 = [11 x i8] c"0123456789\00"
@.str.7 = [19 x i8] c"send() failed: %s\0A\00"
@.str.8 = [10 x i8] c"send %ld\0A\00"
@.str.9 = [19 x i8] c"recv() failed: %s\0A\00"
@.str.10 = [29 x i8] c"recv %ld, body_n %u, fid %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 i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i32
%15 = alloca %struct.sockaddr_in
%16 = alloca [102406 x i8]
%17 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 1, i8* %12
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = load i32, i32* @O_WRONLY
%22 = or i32 %20, %21
%23 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22, i32 420)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %167
31: ; preds = %2
store i32 1024, i32* %8
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 3
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 4
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %167
42: ; preds = %34, %31
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call signext i8 @atoi(i8* %48)
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %53
52: ; preds = %45
store i8 8, i8* %12
br label %53
53: ; preds = %52, %45
br label %54
54: ; preds = %53, %42
%55 = call i32 @memset(%struct.sockaddr_in* %15, i32 0, i32 24)
%56 = load i32, i32* @AF_INET
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %56, i32* %57
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call signext i8 @atoi(i8* %60)
%62 = call i8* @htons(i8 signext %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
store i8* %62, i8** %63
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32 @inet_addr(i8* %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
store i32 %67, i32* %69
%70 = load i32, i32* @AF_INET
%71 = load i32, i32* @SOCK_STREAM
%72 = call i32 @socket(i32 %70, i32 %71, i32 0)
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %80
75: ; preds = %54
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %78)
store i32 1, i32* %3
br label %167
80: ; preds = %54
%81 = load i32, i32* %7
%82 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%83 = call i32 @connect(i32 %81, %struct.sockaddr* %82, i32 24)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %98
85: ; preds = %80
%86 = load i32, i32* @stderr
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 2
%92 = load i8*, i8** %91
%93 = call signext i8 @atoi(i8* %92)
%94 = sext i8 %93 to i32
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %89, i32 %94, i8* %96)
store i32 1, i32* %3
br label %167
98: ; preds = %80
%99 = load i8, i8* %12
%100 = call i8* @htons(i8 signext %99)
%101 = ptrtoint i8* %100 to i8
store i8 %101, i8* %11
store i8 0, i8* %13
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
%104 = call i32 @htonl(i32 %103)
store i32 %104, i32* %14
%105 = getelementptr inbounds [102406 x i8], [102406 x i8]* %16, i64 0, i64 0
%106 = call i32 (i8*, ...) @memcpy(i8* %105, i32* %14, i32 4)
%107 = getelementptr inbounds [102406 x i8], [102406 x i8]* %16, i64 0, i64 0
%108 = getelementptr inbounds i8, i8* %107, i64 6
%109 = call i32 (i8*, ...) @memcpy(i8* %108, i8* %11, i32 2)
%110 = getelementptr inbounds [102406 x i8], [102406 x i8]* %16, i64 0, i64 0
%111 = getelementptr inbounds i8, i8* %110, i64 8
%112 = call i32 (i8*, ...) @memcpy(i8* %111, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%113 = load i32, i32* %7
%114 = getelementptr inbounds [102406 x i8], [102406 x i8]* %16, i64 0, i64 0
%115 = load i32, i32* %6
%116 = add nsw i32 %115, 1
%117 = add nsw i32 8, %116
%118 = call i32 @send(i32 %113, i8* %114, i32 %117, i32 0)
store i32 %118, i32* %10
%119 = load i32, i32* %10
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %126
121: ; preds = %98
%122 = load i32, i32* @stderr
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %124)
store i32 1, i32* %3
br label %167
126: ; preds = %98
%127 = load i32, i32* @stderr
%128 = load i32, i32* %10
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %128)
%130 = load i32, i32* %7
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%132 = call i32 @recv(i32 %130, i8* %131, i32 1024, i32 0)
store i32 %132, i32* %10
%133 = load i32, i32* %10
%134 = icmp eq i32 %133, -1
br i1 %134, label %135, label %140
135: ; preds = %126
%136 = load i32, i32* @stderr
%137 = load i32, i32* @errno
%138 = call i8* @strerror(i32 %137)
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %138)
store i32 1, i32* %3
br label %167
140: ; preds = %126
%141 = load i32, i32* %10
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 %142
store i8 0, i8* %143
%144 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%145 = bitcast i8* %144 to i32*
%146 = load i32, i32* %145
%147 = call i32 @ntohl(i32 %146)
store i32 %147, i32* %14
%148 = load i32, i32* @stderr
%149 = load i32, i32* %10
%150 = load i32, i32* %14
%151 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%152 = getelementptr inbounds i8, i8* %151, i64 8
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 %149, i32 %150, i8* %152)
%154 = load i32, i32* %10
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 %155
store i8 10, i8* %156
%157 = load i32, i32* %9
%158 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%159 = getelementptr inbounds i8, i8* %158, i64 8
%160 = load i32, i32* %14
%161 = add nsw i32 %160, 1
%162 = call i32 @write(i32 %157, i8* %159, i32 %161)
%163 = load i32, i32* %7
%164 = call i32 @close(i32 %163)
%165 = load i32, i32* %9
%166 = call i32 @close(i32 %165)
store i32 0, i32* %3
br label %167
167: ; preds = %140, %135, %121, %85, %75, %37, %26
%168 = load i32, i32* %3
ret i32 %168
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [12 x i8] c"upload_list\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [18 x i8] c"open() failed %s\0A\00"
@errno = global i32 0
@.str.2 = [64 x i8] c"dfs_client_upload <ip> <port> [0|1, upload(default)|upload_sc]\0A\00"
@.str.3 = [37 x i8] c"dfs_client_upload 10.101.69.16 1304\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [21 x i8] c"socket() failed: %s\0A\00"
@.str.5 = [28 x i8] c"connect(%s:%hu) failed: %s\0A\00"
@.str.6 = [11 x i8] c"0123456789\00"
@.str.7 = [19 x i8] c"send() failed: %s\0A\00"
@.str.8 = [10 x i8] c"send %ld\0A\00"
@.str.9 = [19 x i8] c"recv() failed: %s\0A\00"
@.str.10 = [29 x i8] c"recv %ld, body_n %u, fid %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [102406 x i8]
%7 = alloca [1024 x i8]
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [102406 x i8], [102406 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %13, %12
%15 = load i32, i32* @O_WRONLY
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16, i32 420)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %116
24: ; preds = %2
%25 = add i32 %0, -5
%26 = icmp ult i32 %25, -2
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %116
32: ; preds = %24
%33 = icmp eq i32 %0, 4
br i1 %33, label %34, label %40
34: ; preds = %32
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call signext i8 @atoi(i8* %36)
%38 = icmp eq i8 %37, 1
%39 = select i1 %38, i8 8, i8 1
br label %40
40: ; preds = %34, %32
%41 = phi i8 [ 1, %32 ], [ %39, %34 ]
%42 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%43 = load i32, i32* @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %43, i32* %44
%45 = getelementptr inbounds i8*, i8** %1, i64 2
%46 = load i8*, i8** %45
%47 = call signext i8 @atoi(i8* %46)
%48 = call i8* @htons(i8 signext %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %48, i8** %49
%50 = getelementptr inbounds i8*, i8** %1, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @inet_addr(i8* %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* @AF_INET
%55 = load i32, i32* @SOCK_STREAM
%56 = call i32 @socket(i32 %54, i32 %55, i32 0)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %40
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %61)
br label %116
63: ; preds = %40
%64 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%65 = call i32 @connect(i32 %56, %struct.sockaddr* %64, i32 24)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %76
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %50
%70 = load i8*, i8** %45
%71 = call signext i8 @atoi(i8* %70)
%72 = sext i8 %71 to i32
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %69, i32 %72, i8* %74)
br label %116
76: ; preds = %63
%77 = call i8* @htons(i8 signext %41)
%78 = ptrtoint i8* %77 to i64
%79 = trunc i64 %78 to i8
store i8 %79, i8* %3
%80 = call i32 @htonl(i32 undef)
store i32 %80, i32* %4
%81 = call i32 (i8*, ...) @memcpy(i8* %10, i32* %4, i32 4)
%82 = getelementptr inbounds [102406 x i8], [102406 x i8]* %6, i64 0, i64 6
%83 = call i32 (i8*, ...) @memcpy(i8* %82, i8* %3, i32 2)
%84 = getelementptr inbounds [102406 x i8], [102406 x i8]* %6, i64 0, i64 8
%85 = call i32 (i8*, ...) @memcpy(i8* %84, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%86 = call i32 @send(i32 %56, i8* %10, i32 undef, i32 0)
%87 = icmp eq i32 %86, -1
%88 = load i32, i32* @stderr
br i1 %87, label %89, label %93
89: ; preds = %76
%90 = load i32, i32* @errno
%91 = call i8* @strerror(i32 %90)
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %91)
br label %116
93: ; preds = %76
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %86)
%95 = call i32 @recv(i32 %56, i8* %11, i32 1024, i32 0)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %102
97: ; preds = %93
%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 ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %100)
br label %116
102: ; preds = %93
%103 = sext i32 %95 to i64
%104 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %103
store i8 0, i8* %104
%105 = bitcast [1024 x i8]* %7 to i32*
%106 = load i32, i32* %105
%107 = call i32 @ntohl(i32 %106)
store i32 %107, i32* %4
%108 = load i32, i32* @stderr
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 8
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 %95, i32 %107, i8* %109)
store i8 10, i8* %104
%111 = load i32, i32* %4
%112 = add nsw i32 %111, 1
%113 = call i32 @write(i32 %17, i8* %109, i32 %112)
%114 = call i32 @close(i32 %56)
%115 = call i32 @close(i32 %17)
br label %116
116: ; preds = %102, %97, %89, %67, %58, %27, %19
%117 = phi i32 [ -1, %19 ], [ 1, %27 ], [ 1, %58 ], [ 1, %67 ], [ 1, %89 ], [ 1, %97 ], [ 0, %102 ]
ret i32 %117
}