#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int open_socket();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void send_get(int *sock, uint8_t *get, size_t getlen, uint8_t *post,
              int debug) {
  ssize_t socksent = 0;
  size_t curpos = 0;
  *sock = open_socket();
  if (*sock < 0) {
    perror("send_get");
    free(get);
    if (post)
      free(post);
    exit(7);
  }
  while (curpos < getlen) {
    if ((getlen - curpos) >= 512) {
      socksent = send(*sock, get + curpos, 512, 0);
      if (debug)
        fprintf(stderr, "Sent %zd bytes\n", socksent);
      if (socksent < 0) {
        perror("send_get");
        close(*sock);
        free(get);
        if (post)
          free(post);
        exit(7);
      }
    } else {
      socksent = send(*sock, get + curpos, getlen - curpos, 0);
      if (debug)
        fprintf(stderr, "Sent %zd bytes\n", socksent);
      if (socksent < 0) {
        perror("send_get");
        close(*sock);
        free(get);
        if (post)
          free(post);
        exit(7);
      }
    }
    curpos += socksent;
    printf(
        "\r%zd/%zd Bytes written: GET %g%% complete                          ",
        curpos, getlen, ((float)curpos / (float)getlen) * (float)100);
    fflush(stdout);
  }
  printf("\nFinished sending GET. Waiting for response.\n");
}


x86 assembly (clang, -O0):
<send_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <open_socket@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    120b <send_get+0x7b>
lea    0xe25(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     1201 <send_get+0x71>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7,%edi
call   10b0 <exit@plt>
jmp    1210 <send_get+0x80>
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1447 <send_get+0x2b7>
mov    -0x18(%rbp),%rax
sub    -0x38(%rbp),%rax
cmp    $0x200,%rax
jb     12c8 <send_get+0x138>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     127a <send_get+0xea>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd98(%rip),%rsi
call   1080 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
jge    12c3 <send_get+0x133>
lea    0xd78(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12b9 <send_get+0x129>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7,%edi
call   10b0 <exit@plt>
jmp    1361 <send_get+0x1d1>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
sub    -0x38(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1313 <send_get+0x183>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xcff(%rip),%rsi
call   1080 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
jge    135c <send_get+0x1cc>
lea    0xcdf(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     1352 <send_get+0x1c2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7,%edi
call   10b0 <exit@plt>
jmp    1361 <send_get+0x1d1>
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x40(%rbp)
test   %rax,%rax
movss  %xmm0,-0x3c(%rbp)
js     13b9 <send_get+0x229>
movss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x48(%rbp),%rax
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x58(%rbp)
test   %rax,%rax
movss  %xmm0,-0x54(%rbp)
js     1400 <send_get+0x270>
movss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rsi
movss  -0x5c(%rbp),%xmm0
movss  -0x54(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xbe2(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xbf0(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    1210 <send_get+0x80>
lea    0xc13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r13
xor    %eax,%eax
call   1050 <open_socket@plt>
mov    %eax,0x0(%r13)
test   %eax,%eax
js     12db <send_get+0x13b>
mov    %rbx,0x10(%rsp)
test   %rbp,%rbp
je     12c1 <send_get+0x121>
js     11e7 <send_get+0x47>
cvtsi2ss %rbp,%xmm0
jmp    11fe <send_get+0x5e>
mov    %rbp,%rax
shr    %rax
mov    %ebp,%ecx
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %ebx,%ebx
jmp    1251 <send_get+0xb1>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %rbx,%xmm0
divss  0xc(%rsp),%xmm0
mulss  0xdda(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdec(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    $0x1,%al
call   1070 <printf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
cmp    %rbp,%rbx
jae    12c1 <send_get+0x121>
mov    %rbp,%rdx
sub    %rbx,%rdx
mov    0x0(%r13),%edi
lea    (%r15,%rbx,4),%rsi
cmp    $0x200,%rdx
jb     126d <send_get+0xcd>
mov    $0x200,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,%r14
test   %r12d,%r12d
je     1294 <send_get+0xf4>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    %r14,%rdx
call   1090 <fprintf@plt>
test   %r14,%r14
js     12f9 <send_get+0x159>
add    %r14,%rbx
jns    1210 <send_get+0x70>
mov    %rbx,%rax
shr    %rax
mov    %ebx,%ecx
and    $0x1,%ecx
or     %rax,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
jmp    1218 <send_get+0x78>
lea    0xd99(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xd22(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1325 <send_get+0x185>
mov    %rbx,%rdi
jmp    1320 <send_get+0x180>
lea    0xd04(%rip),%rdi
call   10b0 <perror@plt>
mov    0x0(%r13),%edi
call   1080 <close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1325 <send_get+0x185>
call   1030 <free@plt>
mov    $0x7,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"send_get\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Sent %zd bytes\0A\00"
@.str.2 = [68 x i8] c"\0D%zd/%zd Bytes written: GET %g%% complete \00"
@stdout = global i32 0
@.str.3 = [46 x i8] c"\0AFinished sending GET. Waiting for response.\0A\00"
define void @send_get(i32* %0, i32* %1, i64 %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i64 0, i64* %11
store i64 0, i64* %12
%13 = call i32 (...) @open_socket()
%14 = load i32*, i32** %6
store i32 %13, i32* %14
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %5
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%20 = load i32*, i32** %7
%21 = call i32 @free(i32* %20)
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32*, i32** %9
%26 = call i32 @free(i32* %25)
br label %27
27: ; preds = %24, %18
%28 = call i32 @exit(i32 7)
unreachable
29: ; preds = %5
br label %30
30: ; preds = %104, %29
%31 = load i64, i64* %12
%32 = load i64, i64* %8
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %120
34: ; preds = %30
%35 = load i64, i64* %8
%36 = load i64, i64* %12
%37 = sub i64 %35, %36
%38 = icmp uge i64 %37, 512
br i1 %38, label %39, label %70
39: ; preds = %34
%40 = load i32*, i32** %6
%41 = load i32, i32* %40
%42 = load i32*, i32** %7
%43 = load i64, i64* %12
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = call i64 @send(i32 %41, i32* %44, i64 512, i32 0)
store i64 %45, i64* %11
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %39
%49 = load i32, i32* @stderr
%50 = load i64, i64* %11
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %50)
br label %52
52: ; preds = %48, %39
%53 = load i64, i64* %11
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %69
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = load i32*, i32** %7
%61 = call i32 @free(i32* %60)
%62 = load i32*, i32** %9
%63 = icmp ne i32* %62, null
br i1 %63, label %64, label %67
64: ; preds = %55
%65 = load i32*, i32** %9
%66 = call i32 @free(i32* %65)
br label %67
67: ; preds = %64, %55
%68 = call i32 @exit(i32 7)
unreachable
69: ; preds = %52
br label %104
70: ; preds = %34
%71 = load i32*, i32** %6
%72 = load i32, i32* %71
%73 = load i32*, i32** %7
%74 = load i64, i64* %12
%75 = getelementptr inbounds i32, i32* %73, i64 %74
%76 = load i64, i64* %8
%77 = load i64, i64* %12
%78 = sub i64 %76, %77
%79 = call i64 @send(i32 %72, i32* %75, i64 %78, i32 0)
store i64 %79, i64* %11
%80 = load i32, i32* %10
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %70
%83 = load i32, i32* @stderr
%84 = load i64, i64* %11
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %84)
br label %86
86: ; preds = %82, %70
%87 = load i64, i64* %11
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %103
89: ; preds = %86
%90 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%91 = load i32*, i32** %6
%92 = load i32, i32* %91
%93 = call i32 @close(i32 %92)
%94 = load i32*, i32** %7
%95 = call i32 @free(i32* %94)
%96 = load i32*, i32** %9
%97 = icmp ne i32* %96, null
br i1 %97, label %98, label %101
98: ; preds = %89
%99 = load i32*, i32** %9
%100 = call i32 @free(i32* %99)
br label %101
101: ; preds = %98, %89
%102 = call i32 @exit(i32 7)
unreachable
103: ; preds = %86
br label %104
104: ; preds = %103, %69
%105 = load i64, i64* %11
%106 = load i64, i64* %12
%107 = add i64 %106, %105
store i64 %107, i64* %12
%108 = load i64, i64* %12
%109 = load i64, i64* %8
%110 = load i64, i64* %12
%111 = uitofp i64 %110 to float
%112 = load i64, i64* %8
%113 = uitofp i64 %112 to float
%114 = fdiv float %111, %113
%115 = fmul float %114, 1.000000e+02
%116 = fpext float %115 to double
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i64 %108, i64 %109, double %116)
%118 = load i32, i32* @stdout
%119 = call i32 @fflush(i32 %118)
br label %30
120: ; preds = %30
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"send_get\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Sent %zd bytes\0A\00"
@.str.2 = [68 x i8] c"\0D%zd/%zd Bytes written: GET %g%% complete \00"
@stdout = global i32 0
@str = [45 x i8] c"\0AFinished sending GET. Waiting for response.\00"
define void @send_get(i32* nocapture %0, i32* %1, i64 %2, i32* %3, i32 %4) {
%6 = tail call i32 (...) @open_socket()
store i32 %6, i32* %0
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = icmp eq i64 %2, 0
br i1 %9, label %72, label %10
10: ; preds = %8
%11 = icmp eq i32 %4, 0
%12 = uitofp i64 %2 to float
br label %21
13: ; preds = %5
%14 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @free(i32* %1)
%16 = icmp eq i32* %3, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @free(i32* %3)
br label %19
19: ; preds = %17, %13
%20 = tail call i32 @exit(i32 7)
unreachable
21: ; preds = %10, %61
%22 = phi i64 [ 0, %10 ], [ %63, %61 ]
%23 = sub i64 %2, %22
%24 = icmp ugt i64 %23, 511
%25 = load i32, i32* %0
%26 = getelementptr inbounds i32, i32* %1, i64 %22
br i1 %24, label %27, label %44
27: ; preds = %21
%28 = tail call i64 @send(i32 %25, i32* %26, i64 512, i32 0)
br i1 %11, label %32, label %29
29: ; preds = %27
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %28)
br label %32
32: ; preds = %29, %27
%33 = icmp slt i64 %28, 0
br i1 %33, label %34, label %61
34: ; preds = %32
%35 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* %0
%37 = tail call i32 @close(i32 %36)
%38 = tail call i32 @free(i32* %1)
%39 = icmp eq i32* %3, null
br i1 %39, label %42, label %40
40: ; preds = %34
%41 = tail call i32 @free(i32* %3)
br label %42
42: ; preds = %40, %34
%43 = tail call i32 @exit(i32 7)
unreachable
44: ; preds = %21
%45 = tail call i64 @send(i32 %25, i32* %26, i64 %23, i32 0)
br i1 %11, label %49, label %46
46: ; preds = %44
%47 = load i32, i32* @stderr
%48 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %45)
br label %49
49: ; preds = %46, %44
%50 = icmp slt i64 %45, 0
br i1 %50, label %51, label %61
51: ; preds = %49
%52 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%53 = load i32, i32* %0
%54 = tail call i32 @close(i32 %53)
%55 = tail call i32 @free(i32* %1)
%56 = icmp eq i32* %3, null
br i1 %56, label %59, label %57
57: ; preds = %51
%58 = tail call i32 @free(i32* %3)
br label %59
59: ; preds = %57, %51
%60 = tail call i32 @exit(i32 7)
unreachable
61: ; preds = %49, %32
%62 = phi i64 [ %28, %32 ], [ %45, %49 ]
%63 = add i64 %62, %22
%64 = uitofp i64 %63 to float
%65 = fdiv float %64, %12
%66 = fmul float %65, 1.000000e+02
%67 = fpext float %66 to double
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i64 %63, i64 %2, double %67)
%69 = load i32, i32* @stdout
%70 = tail call i32 @fflush(i32 %69)
%71 = icmp ult i64 %63, %2
br i1 %71, label %21, label %72
72: ; preds = %61, %8
%73 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
ret void
}