#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 */

/* Variables and functions */
int /*<<< orphan*/ _my_log(char *, int, char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, scalar_t__, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int do_proxy_cmd(int sock, char *cmd, char *buf, int buflen) {
  int n;
  int n_recved;
  do {
    _my_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/zhongliangkang/twemproxy41/refs/heads/"
            "master/transfer/transfer.c",
            73, "do_proxy_cmd: %s\n", cmd);
  } while (0);
  n = send(sock, cmd, strlen(cmd), 0);
  if (n < 0) {
  } else if (n == (int)strlen(cmd)) {
  } else {
  }
  n_recved = 0;
  while (n_recved < buflen) {
    n = recv(sock, buf + n_recved, buflen, 0);
    if (n <= 0) {
      break;
    }
    n_recved += n;
  }
  if (n_recved >= buflen) {
    do {
      _my_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/zhongliangkang/twemproxy41/refs/heads/"
              "master/transfer/transfer.c",
              93, "ERROR: too much data recved.");
    } while (0);
    buf[buflen - 1] = '\0';
  } else {
    buf[n_recved] = '\0';
  }
  return n_recved;
}


x86 assembly (clang, -O0):
<do_proxy_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rcx
lea    0xe9f(%rip),%rdi
mov    $0x49,%esi
lea    0xf2e(%rip),%rdx
mov    $0x0,%al
call   1040 <_my_log@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ae <do_proxy_cmd+0x6e>
jmp    11da <do_proxy_cmd+0x9a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jne    11d0 <do_proxy_cmd+0x90>
jmp    11d5 <do_proxy_cmd+0x95>
jmp    11d5 <do_proxy_cmd+0x95>
jmp    11da <do_proxy_cmd+0x9a>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1225 <do_proxy_cmd+0xe5>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1217 <do_proxy_cmd+0xd7>
jmp    1225 <do_proxy_cmd+0xe5>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11e1 <do_proxy_cmd+0xa1>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1266 <do_proxy_cmd+0x126>
jmp    1236 <do_proxy_cmd+0xf6>
lea    0xdc3(%rip),%rdi
mov    $0x5d,%esi
lea    0xe64(%rip),%rdx
mov    $0x0,%al
call   1040 <_my_log@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1272 <do_proxy_cmd+0x132>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_proxy_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0xea5(%rip),%rdi
lea    0xf39(%rip),%rdx
xor    %ebx,%ebx
mov    $0x49,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <_my_log@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %r12d,%r12d
jle    11c1 <do_proxy_cmd+0x81>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebx,%rbp
add    %r14,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11e6 <do_proxy_cmd+0xa6>
add    %eax,%ebx
cmp    %r12d,%ebx
jl     11a0 <do_proxy_cmd+0x60>
lea    0xe38(%rip),%rdi
lea    0xede(%rip),%rdx
mov    $0x5d,%esi
xor    %eax,%eax
call   1040 <_my_log@plt>
movslq %r12d,%rax
lea    (%rax,%r14,1),%rbp
add    $0xffffffffffffffff,%rbp
movb   $0x0,0x0(%rbp)
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhongliangkang/twemproxy41/refs/heads/master/transfer/transfer.c\00"
@.str.1 = [18 x i8] c"do_proxy_cmd: %s\0A\00"
@.str.2 = [29 x i8] c"ERROR: too much data recved.\00"
define i32 @do_proxy_cmd(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
br label %11
11: ; preds = %4
%12 = load i8*, i8** %6
%13 = call i32 (i8*, i32, i8*, ...) @_my_log(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = call i32 @send(i32 %15, i8* %16, i64 %18, i32 0)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
br label %32
23: ; preds = %14
%24 = load i32, i32* %9
%25 = load i8*, i8** %6
%26 = call i64 @strlen(i8* %25)
%27 = trunc i64 %26 to i32
%28 = icmp eq i32 %24, %27
br i1 %28, label %29, label %30
29: ; preds = %23
br label %31
30: ; preds = %23
br label %31
31: ; preds = %30, %29
br label %32
32: ; preds = %31, %22
store i32 0, i32* %10
br label %33
33: ; preds = %48, %32
%34 = load i32, i32* %10
%35 = load i32, i32* %8
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load i32, i32* %5
%39 = load i8*, i8** %7
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i32, i32* %8
%44 = call i32 @recv(i32 %38, i8* %42, i32 %43, i32 0)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %37
br label %52
48: ; preds = %37
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = add nsw i32 %50, %49
store i32 %51, i32* %10
br label %33
52: ; preds = %47, %33
%53 = load i32, i32* %10
%54 = load i32, i32* %8
%55 = icmp sge i32 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %52
br label %57
57: ; preds = %56
%58 = call i32 (i8*, i32, i8*, ...) @_my_log(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 93, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57
%60 = load i8*, i8** %7
%61 = load i32, i32* %8
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %60, i64 %63
store i8 0, i8* %64
br label %70
65: ; preds = %52
%66 = load i8*, i8** %7
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %65, %59
%71 = load i32, i32* %10
ret i32 %71
}

LLVM IR (-O2):
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhongliangkang/twemproxy41/refs/heads/master/transfer/transfer.c\00"
@.str.1 = [18 x i8] c"do_proxy_cmd: %s\0A\00"
@.str.2 = [29 x i8] c"ERROR: too much data recved.\00"
define i32 @do_proxy_cmd(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 (i8*, i32, i8*, ...) @_my_log(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i32 @send(i32 %0, i8* %1, i64 %6, i32 0)
%8 = icmp sgt i32 %3, 0
br i1 %8, label %11, label %18
9: ; preds = %11
%10 = icmp slt i32 %17, %3
br i1 %10, label %11, label %18
11: ; preds = %4, %9
%12 = phi i32 [ %17, %9 ], [ 0, %4 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = tail call i32 @recv(i32 %0, i8* %14, i32 %3, i32 0)
%16 = icmp slt i32 %15, 1
%17 = add nsw i32 %15, %12
br i1 %16, label %24, label %9
18: ; preds = %9, %4
%19 = phi i32 [ 0, %4 ], [ %17, %9 ]
%20 = tail call i32 (i8*, i32, i8*, ...) @_my_log(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 93, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%21 = add nsw i32 %3, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %2, i64 %22
br label %24
24: ; preds = %11, %18
%25 = phi i8* [ %23, %18 ], [ %14, %11 ]
%26 = phi i32 [ %19, %18 ], [ %12, %11 ]
store i8 0, i8* %25
ret i32 %26
}