#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 */
scalar_t__ conn_writeback(int, char *, size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gen_err_msg(char *, char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ put_err(int /*<<< orphan*/);
size_t strlen(char const *);
int fwd_write_command(int remote_fd, const char *command, const char *data) {
  size_t len1 = strlen(command);
  size_t len2 = strlen(data);
  size_t len = len1 + len2;
  char *buf = malloc(sizeof(char) * len + 3);
  memcpy(buf, command, len1);
  memcpy(buf + len1, data, len2);
  buf[len] = '\r';
  buf[len + 1] = '\n';
  buf[len + 2] = '\0';
  if (conn_writeback(remote_fd, buf, len + 2) <= 0) {
    if (!0)
      put_err(gen_err_msg(
          "[1;31mERROR:[0m ", "Writing on Remote Socket",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/"
          "refs/heads/master/forward.c",
          242));
    free(buf);
    return -1;
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<fwd_write_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x0,%rax
add    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0xa,0x1(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,0x2(%rax,%rcx,1)
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    $0x2,%rdx
call   1050 <conn_writeback@plt>
cmp    $0x0,%rax
jg     1265 <fwd_write_command+0xf5>
lea    0xdcf(%rip),%rdi
lea    0xddb(%rip),%rsi
lea    0xded(%rip),%rdx
mov    $0xf2,%ecx
call   1070 <gen_err_msg@plt>
mov    %eax,%edi
call   1080 <put_err@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <fwd_write_command+0x105>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwd_write_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,0x4(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%rbp,1),%r14
lea    0x3(%r14),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1060 <memcpy@plt>
lea    (%rbx,%rbp,1),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <memcpy@plt>
movw   $0xa0d,(%rbx,%r14,1)
lea    0x2(,%rbp,1),%rdx
add    %r13,%rdx
movb   $0x0,0x2(%rbx,%r14,1)
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1050 <conn_writeback@plt>
xor    %ebp,%ebp
test   %rax,%rax
jg     121e <fwd_write_command+0xae>
lea    0xe06(%rip),%rdi
lea    0xe12(%rip),%rsi
lea    0xe24(%rip),%rdx
mov    $0xf2,%ecx
call   1070 <gen_err_msg@plt>
mov    %eax,%edi
call   1080 <put_err@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\1B[1;31mERROR:\1B[0m \00"
@.str.1 = [25 x i8] c"Writing on Remote Socket\00"
@.str.2 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/refs/heads/master/forward.c\00"
define i32 @fwd_write_command(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %8
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %9
%16 = load i64, i64* %8
%17 = load i64, i64* %9
%18 = add i64 %16, %17
store i64 %18, i64* %10
%19 = load i64, i64* %10
%20 = mul i64 1, %19
%21 = add i64 %20, 3
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = load i8*, i8** %6
%26 = load i64, i64* %8
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %11
%29 = load i64, i64* %8
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8*, i8** %7
%32 = load i64, i64* %9
%33 = call i32 @memcpy(i8* %30, i8* %31, i64 %32)
%34 = load i8*, i8** %11
%35 = load i64, i64* %10
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 13, i8* %36
%37 = load i8*, i8** %11
%38 = load i64, i64* %10
%39 = add i64 %38, 1
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 10, i8* %40
%41 = load i8*, i8** %11
%42 = load i64, i64* %10
%43 = add i64 %42, 2
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %5
%46 = load i8*, i8** %11
%47 = load i64, i64* %10
%48 = add i64 %47, 2
%49 = call i64 @conn_writeback(i32 %45, i8* %46, i64 %48)
%50 = icmp sle i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %3
%52 = call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.2, i64 0, i64 0), i32 242)
%53 = call i32 @put_err(i32 %52)
%54 = load i8*, i8** %11
%55 = call i32 @free(i8* %54)
store i32 -1, i32* %4
br label %59
56: ; preds = %3
%57 = load i8*, i8** %11
%58 = call i32 @free(i8* %57)
store i32 0, i32* %4
br label %59
59: ; preds = %56, %51
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str = [19 x i8] c"\1B[1;31mERROR:\1B[0m \00"
@.str.1 = [25 x i8] c"Writing on Remote Socket\00"
@.str.2 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/refs/heads/master/forward.c\00"
define i32 @fwd_write_command(i32 %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = add i64 %5, %4
%7 = trunc i64 %6 to i32
%8 = add i32 %7, 3
%9 = tail call i8* @malloc(i32 %8)
%10 = tail call i32 @memcpy(i8* %9, i8* %1, i64 %4)
%11 = getelementptr inbounds i8, i8* %9, i64 %4
%12 = tail call i32 @memcpy(i8* %11, i8* %2, i64 %5)
%13 = getelementptr inbounds i8, i8* %9, i64 %6
store i8 13, i8* %13
%14 = add i64 %6, 1
%15 = getelementptr inbounds i8, i8* %9, i64 %14
store i8 10, i8* %15
%16 = add i64 %6, 2
%17 = getelementptr inbounds i8, i8* %9, i64 %16
store i8 0, i8* %17
%18 = tail call i64 @conn_writeback(i32 %0, i8* %9, i64 %16)
%19 = icmp slt i64 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = tail call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.2, i64 0, i64 0), i32 242)
%22 = tail call i32 @put_err(i32 %21)
br label %23
23: ; preds = %3, %20
%24 = phi i32 [ -1, %20 ], [ 0, %3 ]
%25 = tail call i32 @free(i8* %9)
ret i32 %24
}