#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 dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ Resolve(char *, struct sockaddr_in *, int);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcmp(char const *, char *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int);
int recv(int, char *, size_t, int /*<<< orphan*/);
int send(int, char const *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char const *, char const *, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char const *, char);
int strlen(char const *);
char *strstr(char *, char *);
int postfile(const char *url, const char *path, const char *destfilename,
             const char *username, const char *password, const char *device,
             char *retbuf, size_t retbufsize) {
  char host[100], reqbuf[3000], *p, *buf, reqbuf2[500];
  int rc, f, sk;
  struct sockaddr_in addr;
  off_t filelen;
  static const char *request =
      "POST %s HTTP/1.0\r\n"
      "Content-Type: multipart/form-data; "
      "boundary=---------------------------7d4ca1220568\r\n"
      "User-Agent: Teradeep http client\r\n"
      "Host: %s\r\n"
      "Content-Length: %d\r\n"
      "Cache-Control: no-cache\r\n\r\n";
  static const char *request2 =
      "-----------------------------7d4ca1220568\r\n"
      "Content-Disposition: form-data; name=\"username\"\r\n"
      "\r\n"
      "%s\r\n"
      "-----------------------------7d4ca1220568\r\n"
      "Content-Disposition: form-data; name=\"password\"\r\n"
      "\r\n"
      "%s\r\n"
      "-----------------------------7d4ca1220568\r\n"
      "Content-Disposition: form-data; name=\"datafile\"; filename=\"%s\"\r\n"
      "Content-Type: application/octet-stream\r\n"
      "\r\n";
  static const char *requestend =
      "\r\n-----------------------------7d4ca1220568--\r\n\r\n";
  static const char *request_basicauth =
      "POST %s HTTP/1.0\r\n"
      "Content-Type: multipart/form-data; "
      "boundary=---------------------------7d4ca1220568\r\n"
      "User-Agent: Teradeep http client\r\n"
      "Host: %s\r\n"
      "Authorization: Basic %s\r\n"
      "Content-Length: %d\r\n"
      "Cache-Control: no-cache\r\n\r\n";
  static const char *request_basicauth2 =
      "-----------------------------7d4ca1220568\r\n"
      "Content-Disposition: form-data; name=\"datafile\"; filename=\"%s\"\r\n"
      "Content-Type: application/octet-stream\r\n"
      "\r\n";
  static const char *devicereq =
      "-----------------------------7d4ca1220568\r\n"
      "Content-Disposition: form-data; name=\"device\"\r\n"
      "\r\n"
      "%s\r\n";
  *retbuf = 0;
  f = open(path, O_RDONLY);
  if (f == -1)
    return -1;
  filelen = lseek(f, 0, SEEK_END);
  lseek(f, 0, SEEK_SET);
  if (!memcmp(url, "http://", 7))
    url += 7;
  else if (!memcmp(url, "https://", 8))
    return -6;
  p = strchr(url, '/');
  if (!p)
    p = (char *)url + strlen(url);
  memcpy(host, url, p - url);
  host[p - url] = 0;
  url = p;
  if (!Resolve(host, &addr, 80)) {
    close(f);
    return -3;
  }
  sk = socket(AF_INET, SOCK_STREAM, 0);
  if (sk == -1) {
    close(f);
    return -2;
  }
  if (connect(sk, (struct sockaddr *)&addr, sizeof(addr))) {
    close(f);
    close(sk);
    return -4;
  }
  if (device && *device)
    sprintf(reqbuf2, devicereq, device);
  else
    *reqbuf2 = 0;
  if (password && *password) {
    sprintf(reqbuf2 + strlen(reqbuf2), request2, username, password,
            destfilename);
    sprintf(reqbuf, request, url, host,
            strlen(reqbuf2) + strlen(requestend) + filelen);
  } else {
    sprintf(reqbuf2 + strlen(reqbuf2), request_basicauth2, destfilename);
    sprintf(reqbuf, request_basicauth, url, host, username,
            strlen(reqbuf2) + strlen(requestend) + filelen);
  }
  strcat(reqbuf, reqbuf2);
  rc = send(sk, reqbuf, strlen(reqbuf), 0);
  if (rc < 0) {
    close(f);
    close(sk);
    return -5;
  }
  buf = (char *)malloc(32000);
  while ((rc = read(f, buf, 32000)) > 0) {
    rc = send(sk, buf, rc, 0);
    if (rc <= 0)
      break;
  }
  free(buf);
  close(f);
  if (rc < 0) {
    close(sk);
    return -5;
  }
  rc = send(sk, requestend, strlen(requestend), 0);
  if (rc < 0) {
    close(sk);
    return -5;
  }
  p = retbuf;
  retbufsize--;
  while (p - retbuf < retbufsize) {
    rc = recv(sk, p, retbufsize - (p - retbuf), 0);
    if (rc <= 0)
      break;
    p += rc;
  }
  *p = 0;
  close(sk);
  if (!memcmp(retbuf, "HTTP/1.", 7)) {
    rc = atoi(retbuf + 8);
    if (rc != 200)
      return rc;
    p = strstr(retbuf, "\r\n\r\n");
    if (p) {
      memmove(retbuf, p + 4, strlen(p + 4) + 1);
      return 0;
    }
  }
  return -9;
}


x86 assembly (clang, -O0):
<postfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf30,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0xe78(%rbp)
cmpl   $0xffffffff,-0xe78(%rbp)
jne    12a3 <postfile+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    -0xe78(%rbp),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,-0xe84(%rbp)
mov    -0xe78(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    -0x10(%rbp),%rdi
lea    0x10ac(%rip),%rsi
mov    $0x7,%edx
call   10b0 <memcmp@plt>
cmp    $0x0,%eax
jne    1304 <postfile+0xc4>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
jmp    1333 <postfile+0xf3>
mov    -0x10(%rbp),%rdi
lea    0x1085(%rip),%rsi
mov    $0x8,%edx
call   10b0 <memcmp@plt>
cmp    $0x0,%eax
jne    132e <postfile+0xee>
movl   $0xfffffffa,-0x4(%rbp)
jmp    197f <postfile+0x73f>
jmp    1333 <postfile+0xf3>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
mov    %rax,-0xc68(%rbp)
cmpq   $0x0,-0xc68(%rbp)
jne    1380 <postfile+0x140>
mov    -0x10(%rbp),%rax
mov    %rax,-0xe90(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xe90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xc68(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0xc68(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   10c0 <memcpy@plt>
mov    -0xc68(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0xc68(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
lea    -0xe80(%rbp),%rsi
mov    $0x50,%edx
call   1140 <Resolve@plt>
cmp    $0x0,%eax
jne    13f9 <postfile+0x1b9>
mov    -0xe78(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
mov    0x2bbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0xe7c(%rbp)
cmpl   $0xffffffff,-0xe7c(%rbp)
jne    143c <postfile+0x1fc>
mov    -0xe78(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    -0xe7c(%rbp),%edi
lea    -0xe80(%rbp),%rsi
mov    $0x4,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
je     147f <postfile+0x23f>
mov    -0xe78(%rbp),%edi
call   1090 <close@plt>
mov    -0xe7c(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    197f <postfile+0x73f>
cmpq   $0x0,-0x38(%rbp)
je     14b8 <postfile+0x278>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14b8 <postfile+0x278>
lea    -0xe70(%rbp),%rdi
mov    0x2c40(%rip),%rsi
mov    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1120 <sprintf@plt>
jmp    14bf <postfile+0x27f>
movb   $0x0,-0xe70(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     15a6 <postfile+0x366>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     15a6 <postfile+0x366>
lea    -0xe70(%rbp),%rax
mov    %rax,-0xec0(%rbp)
lea    -0xe70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xec0(%rbp),%rdi
cltq
add    %rax,%rdi
mov    0x2bc1(%rip),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x0,%al
call   1120 <sprintf@plt>
lea    -0xc60(%rbp),%rax
mov    %rax,-0xeb0(%rbp)
mov    0x2b91(%rip),%rax
mov    %rax,-0xea8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xea0(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe98(%rbp)
lea    -0xe70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xeb4(%rbp)
mov    0x2b68(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xeb4(%rbp),%r8d
mov    -0xeb0(%rbp),%rdi
mov    -0xea8(%rbp),%rsi
mov    -0xea0(%rbp),%rdx
mov    -0xe98(%rbp),%rcx
add    %eax,%r8d
add    -0xe84(%rbp),%r8d
mov    $0x0,%al
call   1120 <sprintf@plt>
jmp    1677 <postfile+0x437>
lea    -0xe70(%rbp),%rax
mov    %rax,-0xef8(%rbp)
lea    -0xe70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xef8(%rbp),%rdi
cltq
add    %rax,%rdi
mov    0x2b0d(%rip),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1120 <sprintf@plt>
lea    -0xc60(%rbp),%rax
mov    %rax,-0xee8(%rbp)
mov    0x2ae5(%rip),%rax
mov    %rax,-0xee0(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xed8(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xed0(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xec8(%rbp)
lea    -0xe70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xeec(%rbp)
mov    0x2a99(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xeec(%rbp),%r9d
mov    -0xee8(%rbp),%rdi
mov    -0xee0(%rbp),%rsi
mov    -0xed8(%rbp),%rdx
mov    -0xed0(%rbp),%rcx
mov    -0xec8(%rbp),%r8
add    %eax,%r9d
add    -0xe84(%rbp),%r9d
mov    $0x0,%al
call   1120 <sprintf@plt>
lea    -0xc60(%rbp),%rdi
lea    -0xe70(%rbp),%rsi
call   1110 <strcat@plt>
mov    -0xe7c(%rbp),%eax
mov    %eax,-0xf04(%rbp)
lea    -0xc60(%rbp),%rax
mov    %rax,-0xf00(%rbp)
lea    -0xc60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xf04(%rbp),%edi
mov    -0xf00(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0xe74(%rbp)
cmpl   $0x0,-0xe74(%rbp)
jge    16fb <postfile+0x4bb>
mov    -0xe78(%rbp),%edi
call   1090 <close@plt>
mov    -0xe7c(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    $0x7d00,%edi
call   10d0 <malloc@plt>
mov    %rax,-0xc70(%rbp)
mov    -0xe78(%rbp),%edi
mov    -0xc70(%rbp),%rsi
mov    $0x7d00,%edx
call   10a0 <read@plt>
mov    %eax,-0xe74(%rbp)
cmp    $0x0,%eax
jle    1769 <postfile+0x529>
mov    -0xe7c(%rbp),%edi
mov    -0xc70(%rbp),%rsi
mov    -0xe74(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0xe74(%rbp)
cmpl   $0x0,-0xe74(%rbp)
jg     1764 <postfile+0x524>
jmp    1769 <postfile+0x529>
jmp    170c <postfile+0x4cc>
mov    -0xc70(%rbp),%rdi
call   1030 <free@plt>
mov    -0xe78(%rbp),%edi
call   1090 <close@plt>
cmpl   $0x0,-0xe74(%rbp)
jge    17a4 <postfile+0x564>
mov    -0xe7c(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    -0xe7c(%rbp),%eax
mov    %eax,-0xf14(%rbp)
mov    0x2919(%rip),%rax
mov    %rax,-0xf10(%rbp)
mov    0x290b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xf14(%rbp),%edi
mov    -0xf10(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0xe74(%rbp)
cmpl   $0x0,-0xe74(%rbp)
jge    180a <postfile+0x5ca>
mov    -0xe7c(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    0x10(%rbp),%rax
mov    %rax,-0xc68(%rbp)
mov    0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x18(%rbp)
mov    -0xc68(%rbp),%rax
mov    0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    0x18(%rbp),%rax
jae    1899 <postfile+0x659>
mov    -0xe7c(%rbp),%edi
mov    -0xc68(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    -0xc68(%rbp),%rax
mov    0x10(%rbp),%rcx
sub    %rcx,%rax
sub    %rax,%rdx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0xe74(%rbp)
cmpl   $0x0,-0xe74(%rbp)
jg     187a <postfile+0x63a>
jmp    1899 <postfile+0x659>
mov    -0xe74(%rbp),%ecx
mov    -0xc68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xc68(%rbp)
jmp    1821 <postfile+0x5e1>
mov    -0xc68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xe7c(%rbp),%edi
call   1090 <close@plt>
mov    0x10(%rbp),%rdi
lea    0xae4(%rip),%rsi
mov    $0x7,%edx
call   10b0 <memcmp@plt>
cmp    $0x0,%eax
jne    1978 <postfile+0x738>
mov    0x10(%rbp),%rdi
add    $0x8,%rdi
call   1100 <atoi@plt>
mov    %eax,-0xe74(%rbp)
cmpl   $0xc8,-0xe74(%rbp)
je     18fd <postfile+0x6bd>
mov    -0xe74(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    197f <postfile+0x73f>
mov    0x10(%rbp),%rdi
lea    0x942(%rip),%rsi
call   1150 <strstr@plt>
mov    %rax,-0xc68(%rbp)
cmpq   $0x0,-0xc68(%rbp)
je     1973 <postfile+0x733>
mov    0x10(%rbp),%rax
mov    %rax,-0xf28(%rbp)
mov    -0xc68(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0xf20(%rbp)
mov    -0xc68(%rbp),%rdi
add    $0x4,%rdi
call   1050 <strlen@plt>
mov    -0xf28(%rbp),%rdi
mov    -0xf20(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   10e0 <memmove@plt>
movl   $0x0,-0x4(%rbp)
jmp    197f <postfile+0x73f>
jmp    1978 <postfile+0x738>
movl   $0xfffffff7,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<postfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe58,%rsp
mov    %r9,%r15
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rax
mov    %rdi,%rbx
mov    0xe90(%rsp),%rcx
movb   $0x0,(%rcx)
mov    0x2d63(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     12ee <postfile+0xae>
mov    %eax,%r14d
mov    %rbp,0x28(%rsp)
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,%ebp
mov    0x2d18(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
lea    0x10d1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   10b0 <memcmp@plt>
test   %eax,%eax
je     12f8 <postfile+0xb8>
lea    0x10c1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   10b0 <memcmp@plt>
test   %eax,%eax
jne    12fc <postfile+0xbc>
mov    $0xfffffffa,%eax
jmp    1679 <postfile+0x439>
mov    $0xffffffff,%eax
jmp    1679 <postfile+0x439>
add    $0x7,%rbx
mov    %r13,0x18(%rsp)
mov    %ebp,0xc(%rsp)
mov    %r12,0x20(%rsp)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    132d <postfile+0xed>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%r12
add    %rbx,%r12
mov    %r12,%rbp
sub    %rbx,%rbp
lea    0x30(%rsp),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10c0 <memcpy@plt>
movb   $0x0,0x30(%rsp,%rbp,1)
lea    0x10(%rsp),%rsi
mov    %r13,%rdi
mov    $0x50,%edx
call   1140 <Resolve@plt>
test   %eax,%eax
je     13b1 <postfile+0x171>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
mov    0x2c58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
je     13c3 <postfile+0x183>
mov    %eax,%r13d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1130 <connect@plt>
test   %rax,%rax
je     13d5 <postfile+0x195>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %r13d,%edi
call   1090 <close@plt>
mov    $0xfffffffc,%eax
jmp    1679 <postfile+0x439>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0xfffffffd,%eax
jmp    1679 <postfile+0x439>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0xfffffffe,%eax
jmp    1679 <postfile+0x439>
test   %r15,%r15
je     13fb <postfile+0x1bb>
cmpb   $0x0,(%r15)
je     13fb <postfile+0x1bb>
lea    0xf44(%rip),%rsi
lea    0xa0(%rsp),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1120 <sprintf@plt>
jmp    1403 <postfile+0x1c3>
movb   $0x0,0xa0(%rsp)
mov    0x28(%rsp),%rbp
test   %rbp,%rbp
je     148a <postfile+0x24a>
cmpb   $0x0,0x0(%rbp)
je     148a <postfile+0x24a>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0xa0,%rdi
lea    0xc8c(%rip),%rsi
mov    0x20(%rsp),%rdx
mov    %rbp,%rcx
mov    0x18(%rsp),%r8
xor    %eax,%eax
call   1120 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xdc1(%rip),%rdi
call   1050 <strlen@plt>
add    0xc(%rsp),%ebx
add    %eax,%ebx
lea    0xb92(%rip),%rsi
lea    0x2a0(%rsp),%rdi
lea    0x30(%rsp),%rcx
mov    %r12,%rdx
mov    %ebx,%r8d
xor    %eax,%eax
call   1120 <sprintf@plt>
jmp    14fc <postfile+0x2bc>
lea    0xa0(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0xa0,%rdi
lea    0xcd9(%rip),%rsi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1120 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xd52(%rip),%rdi
call   1050 <strlen@plt>
add    0xc(%rsp),%ebx
add    %eax,%ebx
lea    0xd72(%rip),%rsi
lea    0x2a0(%rsp),%rdi
lea    0x30(%rsp),%rcx
mov    %r12,%rdx
mov    0x20(%rsp),%r8
mov    %ebx,%r9d
xor    %eax,%eax
call   1120 <sprintf@plt>
lea    0x2a0(%rsp),%rbx
lea    0xa0(%rsp),%rsi
mov    %rbx,%rdi
call   1110 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
mov    0xe90(%rsp),%r12
js     1664 <postfile+0x424>
mov    0xe98(%rsp),%r15
mov    $0x7d00,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x7d00,%edx
call   10a0 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    157b <postfile+0x33b>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
jg     1550 <postfile+0x310>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1090 <close@plt>
test   %ebp,%ebp
js     166c <postfile+0x42c>
lea    0xc83(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     166c <postfile+0x42c>
mov    %r12,%rbp
add    $0xffffffffffffffff,%r15
je     15ee <postfile+0x3ae>
xor    %eax,%eax
mov    %r12,%rbp
mov    %r15,%rdx
sub    %rax,%rdx
mov    %r13d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    15ee <postfile+0x3ae>
mov    %eax,%eax
add    %rax,%rbp
mov    %rbp,%rax
sub    %r12,%rax
cmp    %rax,%r15
ja     15c7 <postfile+0x387>
movb   $0x0,0x0(%rbp)
mov    %r13d,%edi
call   1090 <close@plt>
lea    0xd9c(%rip),%rsi
mov    %r12,%rdi
mov    $0x7,%edx
call   10b0 <memcmp@plt>
mov    %eax,%ecx
mov    $0xfffffff7,%eax
test   %ecx,%ecx
jne    1679 <postfile+0x439>
lea    0x8(%r12),%rdi
call   1100 <atoi@plt>
cmp    $0xc8,%eax
jne    1679 <postfile+0x439>
lea    0xc19(%rip),%rsi
mov    %r12,%rdi
call   1150 <strstr@plt>
mov    %rax,%rbx
mov    $0xfffffff7,%eax
test   %rbx,%rbx
je     1679 <postfile+0x439>
add    $0x4,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   10e0 <memmove@plt>
xor    %eax,%eax
jmp    1679 <postfile+0x439>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %r13d,%edi
call   1090 <close@plt>
mov    $0xfffffffb,%eax
add    $0xe58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@postfile.request = internal global i8* getelementptr inbounds ([195 x i8], [195 x i8]* @.str, i32 0, i32 0)
@.str = [195 x i8] c"POST %s HTTP/1.0\0D\0AContent-Type: multipart/form-data; boundary=---------------------------7d4ca1220568\0D\0AUser-Agent: Teradeep http client\0D\0AHost: %s\0D\0AContent-Length: %d\0D\0ACache-Control: no-cache\0D\0A\0D\0A\00"
@postfile.request2 = internal global i8* getelementptr inbounds ([346 x i8], [346 x i8]* @.str.1, i32 0, i32 0)
@.str.1 = [346 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22username\22\0D\0A\0D\0A%s\0D\0A-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22password\22\0D\0A\0D\0A%s\0D\0A-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22datafile\22; filename=\22%s\22\0D\0AContent-Type: application/octet-stream\0D\0A\0D\0A\00"
@postfile.requestend = internal global i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i32 0, i32 0)
@.str.2 = [50 x i8] c"\0D\0A-----------------------------7d4ca1220568--\0D\0A\0D\0A\00"
@postfile.request_basicauth = internal global i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str.3, i32 0, i32 0)
@.str.3 = [220 x i8] c"POST %s HTTP/1.0\0D\0AContent-Type: multipart/form-data; boundary=---------------------------7d4ca1220568\0D\0AUser-Agent: Teradeep http client\0D\0AHost: %s\0D\0AAuthorization: Basic %s\0D\0AContent-Length: %d\0D\0ACache-Control: no-cache\0D\0A\0D\0A\00"
@postfile.request_basicauth2 = internal global i8* getelementptr inbounds ([150 x i8], [150 x i8]* @.str.4, i32 0, i32 0)
@.str.4 = [150 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22datafile\22; filename=\22%s\22\0D\0AContent-Type: application/octet-stream\0D\0A\0D\0A\00"
@postfile.devicereq = internal global i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.5, i32 0, i32 0)
@.str.5 = [97 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22device\22\0D\0A\0D\0A%s\0D\0A\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [8 x i8] c"http://\00"
@.str.7 = [9 x i8] c"https://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [8 x i8] c"HTTP/1.\00"
@.str.9 = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @postfile(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i64 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca [100 x i8]
%19 = alloca [3000 x i8]
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca [500 x i8]
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca %struct.sockaddr_in
%27 = alloca i32
store i8* %0, i8** %10
store i8* %1, i8** %11
store i8* %2, i8** %12
store i8* %3, i8** %13
store i8* %4, i8** %14
store i8* %5, i8** %15
store i8* %6, i8** %16
store i64 %7, i64* %17
%28 = load i8*, i8** %16
store i8 0, i8* %28
%29 = load i8*, i8** %11
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %24
%32 = load i32, i32* %24
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %8
store i32 -1, i32* %9
br label %291
35: ; preds = %8
%36 = load i32, i32* %24
%37 = load i32, i32* @SEEK_END
%38 = call i32 @lseek(i32 %36, i32 0, i32 %37)
store i32 %38, i32* %27
%39 = load i32, i32* %24
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @lseek(i32 %39, i32 0, i32 %40)
%42 = load i8*, i8** %10
%43 = call i32 @memcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %35
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i64 7
store i8* %47, i8** %10
br label %54
48: ; preds = %35
%49 = load i8*, i8** %10
%50 = call i32 @memcmp(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 8)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %48
store i32 -6, i32* %9
br label %291
53: ; preds = %48
br label %54
54: ; preds = %53, %45
%55 = load i8*, i8** %10
%56 = call i8* @strchr(i8* %55, i8 signext 47)
store i8* %56, i8** %20
%57 = load i8*, i8** %20
%58 = icmp ne i8* %57, null
br i1 %58, label %65, label %59
59: ; preds = %54
%60 = load i8*, i8** %10
%61 = load i8*, i8** %10
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
store i8* %64, i8** %20
br label %65
65: ; preds = %59, %54
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%67 = load i8*, i8** %10
%68 = load i8*, i8** %20
%69 = load i8*, i8** %10
%70 = ptrtoint i8* %68 to i64
%71 = ptrtoint i8* %69 to i64
%72 = sub i64 %70, %71
%73 = trunc i64 %72 to i32
%74 = call i32 @memcpy(i8* %66, i8* %67, i32 %73)
%75 = load i8*, i8** %20
%76 = load i8*, i8** %10
%77 = ptrtoint i8* %75 to i64
%78 = ptrtoint i8* %76 to i64
%79 = sub i64 %77, %78
%80 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %20
store i8* %81, i8** %10
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%83 = call i32 @Resolve(i8* %82, %struct.sockaddr_in* %26, i32 80)
%84 = icmp ne i32 %83, 0
br i1 %84, label %88, label %85
85: ; preds = %65
%86 = load i32, i32* %24
%87 = call i32 @close(i32 %86)
store i32 -3, i32* %9
br label %291
88: ; preds = %65
%89 = load i32, i32* @AF_INET
%90 = load i32, i32* @SOCK_STREAM
%91 = call i32 @socket(i32 %89, i32 %90, i32 0)
store i32 %91, i32* %25
%92 = load i32, i32* %25
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %88
%95 = load i32, i32* %24
%96 = call i32 @close(i32 %95)
store i32 -2, i32* %9
br label %291
97: ; preds = %88
%98 = load i32, i32* %25
%99 = bitcast %struct.sockaddr_in* %26 to %struct.sockaddr*
%100 = call i64 @connect(i32 %98, %struct.sockaddr* %99, i32 4)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %107
102: ; preds = %97
%103 = load i32, i32* %24
%104 = call i32 @close(i32 %103)
%105 = load i32, i32* %25
%106 = call i32 @close(i32 %105)
store i32 -4, i32* %9
br label %291
107: ; preds = %97
%108 = load i8*, i8** %15
%109 = icmp ne i8* %108, null
br i1 %109, label %110, label %120
110: ; preds = %107
%111 = load i8*, i8** %15
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %110
%116 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%117 = load i8*, i8** @postfile.devicereq
%118 = load i8*, i8** %15
%119 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %116, i8* %117, i8* %118)
br label %122
120: ; preds = %110, %107
%121 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
store i8 0, i8* %121
br label %122
122: ; preds = %120, %115
%123 = load i8*, i8** %14
%124 = icmp ne i8* %123, null
br i1 %124, label %125, label %153
125: ; preds = %122
%126 = load i8*, i8** %14
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %153
130: ; preds = %125
%131 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%132 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%133 = call i32 @strlen(i8* %132)
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %131, i64 %134
%136 = load i8*, i8** @postfile.request2
%137 = load i8*, i8** %13
%138 = load i8*, i8** %14
%139 = load i8*, i8** %12
%140 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %135, i8* %136, i8* %137, i8* %138, i8* %139)
%141 = getelementptr inbounds [3000 x i8], [3000 x i8]* %19, i64 0, i64 0
%142 = load i8*, i8** @postfile.request
%143 = load i8*, i8** %10
%144 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%145 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%146 = call i32 @strlen(i8* %145)
%147 = load i8*, i8** @postfile.requestend
%148 = call i32 @strlen(i8* %147)
%149 = add nsw i32 %146, %148
%150 = load i32, i32* %27
%151 = add nsw i32 %149, %150
%152 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %141, i8* %142, i8* %143, i8* %144, i32 %151)
br label %175
153: ; preds = %125, %122
%154 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%155 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%156 = call i32 @strlen(i8* %155)
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i8, i8* %154, i64 %157
%159 = load i8*, i8** @postfile.request_basicauth2
%160 = load i8*, i8** %12
%161 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %158, i8* %159, i8* %160)
%162 = getelementptr inbounds [3000 x i8], [3000 x i8]* %19, i64 0, i64 0
%163 = load i8*, i8** @postfile.request_basicauth
%164 = load i8*, i8** %10
%165 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 0, i64 0
%166 = load i8*, i8** %13
%167 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%168 = call i32 @strlen(i8* %167)
%169 = load i8*, i8** @postfile.requestend
%170 = call i32 @strlen(i8* %169)
%171 = add nsw i32 %168, %170
%172 = load i32, i32* %27
%173 = add nsw i32 %171, %172
%174 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %162, i8* %163, i8* %164, i8* %165, i8* %166, i32 %173)
br label %175
175: ; preds = %153, %130
%176 = getelementptr inbounds [3000 x i8], [3000 x i8]* %19, i64 0, i64 0
%177 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%178 = call i32 @strcat(i8* %176, i8* %177)
%179 = load i32, i32* %25
%180 = getelementptr inbounds [3000 x i8], [3000 x i8]* %19, i64 0, i64 0
%181 = getelementptr inbounds [3000 x i8], [3000 x i8]* %19, i64 0, i64 0
%182 = call i32 @strlen(i8* %181)
%183 = call i32 @send(i32 %179, i8* %180, i32 %182, i32 0)
store i32 %183, i32* %23
%184 = load i32, i32* %23
%185 = icmp slt i32 %184, 0
br i1 %185, label %186, label %191
186: ; preds = %175
%187 = load i32, i32* %24
%188 = call i32 @close(i32 %187)
%189 = load i32, i32* %25
%190 = call i32 @close(i32 %189)
store i32 -5, i32* %9
br label %291
191: ; preds = %175
%192 = call i64 @malloc(i32 32000)
%193 = inttoptr i64 %192 to i8*
store i8* %193, i8** %21
br label %194
194: ; preds = %207, %191
%195 = load i32, i32* %24
%196 = load i8*, i8** %21
%197 = call i32 @read(i32 %195, i8* %196, i32 32000)
store i32 %197, i32* %23
%198 = icmp sgt i32 %197, 0
br i1 %198, label %199, label %208
199: ; preds = %194
%200 = load i32, i32* %25
%201 = load i8*, i8** %21
%202 = load i32, i32* %23
%203 = call i32 @send(i32 %200, i8* %201, i32 %202, i32 0)
store i32 %203, i32* %23
%204 = load i32, i32* %23
%205 = icmp sle i32 %204, 0
br i1 %205, label %206, label %207
206: ; preds = %199
br label %208
207: ; preds = %199
br label %194
208: ; preds = %206, %194
%209 = load i8*, i8** %21
%210 = call i32 @free(i8* %209)
%211 = load i32, i32* %24
%212 = call i32 @close(i32 %211)
%213 = load i32, i32* %23
%214 = icmp slt i32 %213, 0
br i1 %214, label %215, label %218
215: ; preds = %208
%216 = load i32, i32* %25
%217 = call i32 @close(i32 %216)
store i32 -5, i32* %9
br label %291
218: ; preds = %208
%219 = load i32, i32* %25
%220 = load i8*, i8** @postfile.requestend
%221 = load i8*, i8** @postfile.requestend
%222 = call i32 @strlen(i8* %221)
%223 = call i32 @send(i32 %219, i8* %220, i32 %222, i32 0)
store i32 %223, i32* %23
%224 = load i32, i32* %23
%225 = icmp slt i32 %224, 0
br i1 %225, label %226, label %229
226: ; preds = %218
%227 = load i32, i32* %25
%228 = call i32 @close(i32 %227)
store i32 -5, i32* %9
br label %291
229: ; preds = %218
%230 = load i8*, i8** %16
store i8* %230, i8** %20
%231 = load i64, i64* %17
%232 = add i64 %231, -1
store i64 %232, i64* %17
br label %233
233: ; preds = %255, %229
%234 = load i8*, i8** %20
%235 = load i8*, i8** %16
%236 = ptrtoint i8* %234 to i64
%237 = ptrtoint i8* %235 to i64
%238 = sub i64 %236, %237
%239 = load i64, i64* %17
%240 = icmp ult i64 %238, %239
br i1 %240, label %241, label %260
241: ; preds = %233
%242 = load i32, i32* %25
%243 = load i8*, i8** %20
%244 = load i64, i64* %17
%245 = load i8*, i8** %20
%246 = load i8*, i8** %16
%247 = ptrtoint i8* %245 to i64
%248 = ptrtoint i8* %246 to i64
%249 = sub i64 %247, %248
%250 = sub i64 %244, %249
%251 = call i32 @recv(i32 %242, i8* %243, i64 %250, i32 0)
store i32 %251, i32* %23
%252 = load i32, i32* %23
%253 = icmp sle i32 %252, 0
br i1 %253, label %254, label %255
254: ; preds = %241
br label %260
255: ; preds = %241
%256 = load i32, i32* %23
%257 = load i8*, i8** %20
%258 = sext i32 %256 to i64
%259 = getelementptr inbounds i8, i8* %257, i64 %258
store i8* %259, i8** %20
br label %233
260: ; preds = %254, %233
%261 = load i8*, i8** %20
store i8 0, i8* %261
%262 = load i32, i32* %25
%263 = call i32 @close(i32 %262)
%264 = load i8*, i8** %16
%265 = call i32 @memcmp(i8* %264, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%266 = icmp ne i32 %265, 0
br i1 %266, label %290, label %267
267: ; preds = %260
%268 = load i8*, i8** %16
%269 = getelementptr inbounds i8, i8* %268, i64 8
%270 = call i32 @atoi(i8* %269)
store i32 %270, i32* %23
%271 = load i32, i32* %23
%272 = icmp ne i32 %271, 200
br i1 %272, label %273, label %275
273: ; preds = %267
%274 = load i32, i32* %23
store i32 %274, i32* %9
br label %291
275: ; preds = %267
%276 = load i8*, i8** %16
%277 = call i8* @strstr(i8* %276, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
store i8* %277, i8** %20
%278 = load i8*, i8** %20
%279 = icmp ne i8* %278, null
br i1 %279, label %280, label %289
280: ; preds = %275
%281 = load i8*, i8** %16
%282 = load i8*, i8** %20
%283 = getelementptr inbounds i8, i8* %282, i64 4
%284 = load i8*, i8** %20
%285 = getelementptr inbounds i8, i8* %284, i64 4
%286 = call i32 @strlen(i8* %285)
%287 = add nsw i32 %286, 1
%288 = call i32 @memmove(i8* %281, i8* %283, i32 %287)
store i32 0, i32* %9
br label %291
289: ; preds = %275
br label %290
290: ; preds = %289, %260
store i32 -9, i32* %9
br label %291
291: ; preds = %290, %280, %273, %226, %215, %186, %102, %94, %85, %52, %34
%292 = load i32, i32* %9
ret i32 %292
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [195 x i8] c"POST %s HTTP/1.0\0D\0AContent-Type: multipart/form-data; boundary=---------------------------7d4ca1220568\0D\0AUser-Agent: Teradeep http client\0D\0AHost: %s\0D\0AContent-Length: %d\0D\0ACache-Control: no-cache\0D\0A\0D\0A\00"
@.str.1 = [346 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22username\22\0D\0A\0D\0A%s\0D\0A-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22password\22\0D\0A\0D\0A%s\0D\0A-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22datafile\22; filename=\22%s\22\0D\0AContent-Type: application/octet-stream\0D\0A\0D\0A\00"
@.str.2 = [50 x i8] c"\0D\0A-----------------------------7d4ca1220568--\0D\0A\0D\0A\00"
@.str.3 = [220 x i8] c"POST %s HTTP/1.0\0D\0AContent-Type: multipart/form-data; boundary=---------------------------7d4ca1220568\0D\0AUser-Agent: Teradeep http client\0D\0AHost: %s\0D\0AAuthorization: Basic %s\0D\0AContent-Length: %d\0D\0ACache-Control: no-cache\0D\0A\0D\0A\00"
@.str.4 = [150 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22datafile\22; filename=\22%s\22\0D\0AContent-Type: application/octet-stream\0D\0A\0D\0A\00"
@.str.5 = [97 x i8] c"-----------------------------7d4ca1220568\0D\0AContent-Disposition: form-data; name=\22device\22\0D\0A\0D\0A%s\0D\0A\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [8 x i8] c"http://\00"
@.str.7 = [9 x i8] c"https://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.8 = [8 x i8] c"HTTP/1.\00"
@.str.9 = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @postfile(i8* %0, i8* nocapture %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i64 %7) {
%9 = alloca [100 x i8]
%10 = alloca [3000 x i8]
%11 = alloca [500 x i8]
%12 = alloca %struct.sockaddr_in
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [3000 x i8], [3000 x i8]* %10, i64 0, i64 0
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %11, i64 0, i64 0
%16 = bitcast %struct.sockaddr_in* %12 to i8*
store i8 0, i8* %6
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %1, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %162, label %20
20: ; preds = %8
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @lseek(i32 %18, i32 0, i32 %21)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @lseek(i32 %18, i32 0, i32 %23)
%25 = tail call i32 @memcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = getelementptr inbounds i8, i8* %0, i64 7
br label %32
29: ; preds = %20
%30 = tail call i32 @memcmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 8)
%31 = icmp eq i32 %30, 0
br i1 %31, label %162, label %32
32: ; preds = %29, %27
%33 = phi i8* [ %0, %29 ], [ %28, %27 ]
%34 = tail call i8* @strchr(i8* dereferenceable(1) %33, i8 signext 47)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = tail call i32 @strlen(i8* %33)
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %33, i64 %38
br label %40
40: ; preds = %36, %32
%41 = phi i8* [ %34, %32 ], [ %39, %36 ]
%42 = ptrtoint i8* %41 to i64
%43 = ptrtoint i8* %33 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
%46 = call i32 @memcpy(i8* %13, i8* %33, i32 %45)
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %44
store i8 0, i8* %47
%48 = call i32 @Resolve(i8* %13, %struct.sockaddr_in* %12, i32 80)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %40
%51 = call i32 @close(i32 %18)
br label %162
52: ; preds = %40
%53 = load i32, i32* @AF_INET
%54 = load i32, i32* @SOCK_STREAM
%55 = call i32 @socket(i32 %53, i32 %54, i32 0)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @close(i32 %18)
br label %162
59: ; preds = %52
%60 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%61 = call i64 @connect(i32 %55, %struct.sockaddr* %60, i32 4)
%62 = icmp eq i64 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %59
%64 = call i32 @close(i32 %18)
%65 = call i32 @close(i32 %55)
br label %162
66: ; preds = %59
%67 = icmp eq i8* %5, null
br i1 %67, label %73, label %68
68: ; preds = %66
%69 = load i8, i8* %5
%70 = icmp eq i8 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([97 x i8], [97 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %74
73: ; preds = %68, %66
store i8 0, i8* %15
br label %74
74: ; preds = %73, %71
%75 = icmp eq i8* %4, null
br i1 %75, label %89, label %76
76: ; preds = %74
%77 = load i8, i8* %4
%78 = icmp eq i8 %77, 0
br i1 %78, label %89, label %79
79: ; preds = %76
%80 = call i32 @strlen(i8* %15)
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [500 x i8], [500 x i8]* %11, i64 0, i64 %81
%83 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %82, i8* dereferenceable(1) getelementptr inbounds ([346 x i8], [346 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4, i8* %2)
%84 = call i32 @strlen(i8* %15)
%85 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%86 = add i32 %84, %22
%87 = add i32 %86, %85
%88 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([195 x i8], [195 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %13, i32 %87)
br label %99
89: ; preds = %76, %74
%90 = call i32 @strlen(i8* %15)
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [500 x i8], [500 x i8]* %11, i64 0, i64 %91
%93 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %92, i8* dereferenceable(1) getelementptr inbounds ([150 x i8], [150 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%94 = call i32 @strlen(i8* %15)
%95 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%96 = add i32 %94, %22
%97 = add i32 %96, %95
%98 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([220 x i8], [220 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %13, i8* %3, i32 %97)
br label %99
99: ; preds = %89, %79
%100 = call i32 @strcat(i8* %14, i8* %15)
%101 = call i32 @strlen(i8* %14)
%102 = call i32 @send(i32 %55, i8* %14, i32 %101, i32 0)
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %99
%105 = call i32 @close(i32 %18)
%106 = call i32 @close(i32 %55)
br label %162
107: ; preds = %99
%108 = call i64 @malloc(i32 32000)
%109 = inttoptr i64 %108 to i8*
br label %110
110: ; preds = %113, %107
%111 = call i32 @read(i32 %18, i8* %109, i32 32000)
%112 = icmp sgt i32 %111, 0
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = call i32 @send(i32 %55, i8* %109, i32 %111, i32 0)
%115 = icmp slt i32 %114, 1
br i1 %115, label %116, label %110
116: ; preds = %113, %110
%117 = phi i32 [ %114, %113 ], [ %111, %110 ]
%118 = call i32 @free(i8* %109)
%119 = call i32 @close(i32 %18)
%120 = icmp slt i32 %117, 0
br i1 %120, label %121, label %123
121: ; preds = %116
%122 = call i32 @close(i32 %55)
br label %162
123: ; preds = %116
%124 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%125 = call i32 @send(i32 %55, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %124, i32 0)
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 @close(i32 %55)
br label %162
129: ; preds = %123
%130 = add i64 %7, -1
%131 = ptrtoint i8* %6 to i64
%132 = icmp eq i64 %130, 0
br i1 %132, label %145, label %133
133: ; preds = %129, %139
%134 = phi i64 [ %143, %139 ], [ 0, %129 ]
%135 = phi i8* [ %141, %139 ], [ %6, %129 ]
%136 = sub i64 %130, %134
%137 = call i32 @recv(i32 %55, i8* %135, i64 %136, i32 0)
%138 = icmp slt i32 %137, 1
br i1 %138, label %145, label %139
139: ; preds = %133
%140 = zext i32 %137 to i64
%141 = getelementptr inbounds i8, i8* %135, i64 %140
%142 = ptrtoint i8* %141 to i64
%143 = sub i64 %142, %131
%144 = icmp ugt i64 %130, %143
br i1 %144, label %133, label %145
145: ; preds = %139, %133, %129
%146 = phi i8* [ %6, %129 ], [ %135, %133 ], [ %141, %139 ]
store i8 0, i8* %146
%147 = call i32 @close(i32 %55)
%148 = call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %162
150: ; preds = %145
%151 = getelementptr inbounds i8, i8* %6, i64 8
%152 = call i32 @atoi(i8* %151)
%153 = icmp eq i32 %152, 200
br i1 %153, label %154, label %162
154: ; preds = %150
%155 = call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%156 = icmp eq i8* %155, null
br i1 %156, label %162, label %157
157: ; preds = %154
%158 = getelementptr inbounds i8, i8* %155, i64 4
%159 = call i32 @strlen(i8* %158)
%160 = add nsw i32 %159, 1
%161 = call i32 @memmove(i8* %6, i8* %158, i32 %160)
br label %162
162: ; preds = %145, %154, %150, %29, %8, %157, %127, %121, %104, %63, %57, %50
%163 = phi i32 [ -2, %57 ], [ -4, %63 ], [ -5, %104 ], [ -5, %121 ], [ -5, %127 ], [ 0, %157 ], [ -3, %50 ], [ -1, %8 ], [ -6, %29 ], [ %152, %150 ], [ -9, %154 ], [ -9, %145 ]
ret i32 %163
}