#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*/ fprintf(int /*<<< orphan*/, char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
void sendRawMsg(int sockFD, char *preMsg, char *rawMsg) {
  int bytesSent, rawLen, preLen, sent, loop;
  char cap;
  cap = '\n';
  bytesSent = 0;
  loop = 0;
  preLen = (preMsg != NULL) ? strlen(preMsg) : 0;
  rawLen = (rawMsg != NULL) ? strlen(rawMsg) : 0;
  while (bytesSent < preLen) {
    sent = send(sockFD, preMsg + bytesSent, preLen - bytesSent, 0);
    if (sent > 0) {
      bytesSent += sent;
    } else if (send < 0) {
      fprintf(stderr, "Error thrown in sending message\n");
      break;
    }
    if (loop++ > 100) {
      fprintf(stderr, "Error, timed out in sending message\n");
    }
  }
  loop = 0;
  bytesSent = 0;
  while (bytesSent < rawLen) {
    sent = send(sockFD, rawMsg + bytesSent, rawLen - bytesSent, 0);
    if (sent > 0) {
      bytesSent += sent;
    } else if (send < 0) {
      fprintf(stderr, "Error thrown in sending message\n");
      break;
    }
    if (loop++ > 100) {
      fprintf(stderr, "Error, timed out in sending message\n");
    }
  }
  sent = 0;
  loop = 0;
  while (sent == 0) {
    sent = send(sockFD, &cap, 1, 0);
    if (sent < 0) {
      fprintf(stderr, "Error thrown in capping message\n");
    }
    if (loop++ > 100) {
      fprintf(stderr, "Error, timed out in sending message cap\n");
    }
  }
}


x86 assembly (clang, -O0):
<sendRawMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0xa,-0x2d(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <sendRawMsg+0x41>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
jmp    117b <sendRawMsg+0x4b>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <sendRawMsg+0x4b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119d <sendRawMsg+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
jmp    11a7 <sendRawMsg+0x77>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11a7 <sendRawMsg+0x77>
mov    -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    124b <sendRawMsg+0x11b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
sub    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11ef <sendRawMsg+0xbf>
mov    -0x28(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    121d <sendRawMsg+0xed>
xor    %eax,%eax
test   $0x1,%al
jne    11fe <sendRawMsg+0xce>
jmp    1218 <sendRawMsg+0xe8>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
jmp    124b <sendRawMsg+0x11b>
jmp    121d <sendRawMsg+0xed>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x64,%eax
jle    1246 <sendRawMsg+0x116>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11ad <sendRawMsg+0x7d>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12f7 <sendRawMsg+0x1c7>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%edx
sub    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    129b <sendRawMsg+0x16b>
mov    -0x28(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    12c9 <sendRawMsg+0x199>
xor    %eax,%eax
test   $0x1,%al
jne    12aa <sendRawMsg+0x17a>
jmp    12c4 <sendRawMsg+0x194>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12f7 <sendRawMsg+0x1c7>
jmp    12c9 <sendRawMsg+0x199>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x64,%eax
jle    12f2 <sendRawMsg+0x1c2>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1259 <sendRawMsg+0x129>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1372 <sendRawMsg+0x242>
mov    -0x4(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1344 <sendRawMsg+0x214>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x64,%eax
jle    136d <sendRawMsg+0x23d>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1305 <sendRawMsg+0x1d5>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendRawMsg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
movb   $0xa,0xf(%rsp)
xor    %r12d,%r12d
mov    $0x0,%ebp
test   %rsi,%rsi
je     1163 <sendRawMsg+0x33>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %r14,%r14
je     1173 <sendRawMsg+0x43>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,0x10(%rsp)
test   %ebp,%ebp
jle    11d4 <sendRawMsg+0xa4>
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    1199 <sendRawMsg+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13d
cmp    %r14d,%ebp
jle    11d4 <sendRawMsg+0xa4>
mov    %r14d,%esi
add    %rbx,%rsi
mov    %ebp,%edx
sub    %r14d,%edx
mov    %r15d,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
test   %eax,%eax
jns    11b4 <sendRawMsg+0x84>
xor    %eax,%eax
add    %eax,%r14d
cmp    $0x65,%r13d
jb     1190 <sendRawMsg+0x60>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1190 <sendRawMsg+0x60>
test   %r12d,%r12d
jle    1229 <sendRawMsg+0xf9>
xor    %ebp,%ebp
mov    0x2dfe(%rip),%r13
lea    0xe17(%rip),%r14
xor    %ebx,%ebx
jmp    11f8 <sendRawMsg+0xc8>
nopl   (%rax)
add    $0x1,%ebp
cmp    %ebx,%r12d
jle    1229 <sendRawMsg+0xf9>
mov    %ebx,%esi
add    0x10(%rsp),%rsi
mov    %r12d,%edx
sub    %ebx,%edx
mov    %r15d,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
test   %eax,%eax
jns    1214 <sendRawMsg+0xe4>
xor    %eax,%eax
add    %eax,%ebx
cmp    $0x65,%ebp
jb     11f0 <sendRawMsg+0xc0>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
jmp    11f0 <sendRawMsg+0xc0>
xor    %ebx,%ebx
lea    0xf(%rsp),%r12
mov    0x2da9(%rip),%r14
lea    0xe08(%rip),%r13
jmp    1247 <sendRawMsg+0x117>
add    $0x1,%ebx
test   %ebp,%ebp
jne    1291 <sendRawMsg+0x161>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1270 <sendRawMsg+0x140>
cmp    $0x65,%ebx
jb     1240 <sendRawMsg+0x110>
jmp    1284 <sendRawMsg+0x154>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edi
lea    0xdab(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x65,%ebx
jb     1240 <sendRawMsg+0x110>
mov    (%r14),%edi
mov    %r13,%rsi
call   1050 <fprintf@plt>
jmp    1240 <sendRawMsg+0x110>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Error thrown in sending message\0A\00"
@.str.1 = [37 x i8] c"Error, timed out in sending message\0A\00"
@.str.2 = [33 x i8] c"Error thrown in capping message\0A\00"
@.str.3 = [41 x i8] c"Error, timed out in sending message cap\0A\00"
define void @sendRawMsg(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8 10, i8* %12
store i32 0, i32* %7
store i32 0, i32* %11
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
br label %19
18: ; preds = %3
br label %19
19: ; preds = %18, %15
%20 = phi i32 [ %17, %15 ], [ 0, %18 ]
store i32 %20, i32* %9
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
br label %27
26: ; preds = %19
br label %27
27: ; preds = %26, %23
%28 = phi i32 [ %25, %23 ], [ 0, %26 ]
store i32 %28, i32* %8
br label %29
29: ; preds = %61, %27
%30 = load i32, i32* %7
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %62
33: ; preds = %29
%34 = load i32, i32* %4
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %9
%40 = load i32, i32* %7
%41 = sub nsw i32 %39, %40
%42 = call i32 @send(i32 %34, i8* %38, i32 %41, i32 0)
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %33
%46 = load i32, i32* %10
%47 = load i32, i32* %7
%48 = add nsw i32 %47, %46
store i32 %48, i32* %7
br label %54
49: ; preds = %33
br i1 false, label %50, label %53
50: ; preds = %49
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %62
53: ; preds = %49
br label %54
54: ; preds = %53, %45
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
%57 = icmp sgt i32 %55, 100
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %61
61: ; preds = %58, %54
br label %29
62: ; preds = %50, %29
store i32 0, i32* %11
store i32 0, i32* %7
br label %63
63: ; preds = %95, %62
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %96
67: ; preds = %63
%68 = load i32, i32* %4
%69 = load i8*, i8** %6
%70 = load i32, i32* %7
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i32, i32* %8
%74 = load i32, i32* %7
%75 = sub nsw i32 %73, %74
%76 = call i32 @send(i32 %68, i8* %72, i32 %75, i32 0)
store i32 %76, i32* %10
%77 = load i32, i32* %10
%78 = icmp sgt i32 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %67
%80 = load i32, i32* %10
%81 = load i32, i32* %7
%82 = add nsw i32 %81, %80
store i32 %82, i32* %7
br label %88
83: ; preds = %67
br i1 false, label %84, label %87
84: ; preds = %83
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %96
87: ; preds = %83
br label %88
88: ; preds = %87, %79
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 1
store i32 %90, i32* %11
%91 = icmp sgt i32 %89, 100
br i1 %91, label %92, label %95
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %95
95: ; preds = %92, %88
br label %63
96: ; preds = %84, %63
store i32 0, i32* %10
store i32 0, i32* %11
br label %97
97: ; preds = %115, %96
%98 = load i32, i32* %10
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %116
100: ; preds = %97
%101 = load i32, i32* %4
%102 = call i32 @send(i32 %101, i8* %12, i32 1, i32 0)
store i32 %102, i32* %10
%103 = load i32, i32* %10
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %108
105: ; preds = %100
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %108
108: ; preds = %105, %100
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
store i32 %110, i32* %11
%111 = icmp sgt i32 %109, 100
br i1 %111, label %112, label %115
112: ; preds = %108
%113 = load i32, i32* @stderr
%114 = call i32 @fprintf(i32 %113, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %115
115: ; preds = %112, %108
br label %97
116: ; preds = %97
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [37 x i8] c"Error, timed out in sending message\0A\00"
@.str.2 = [33 x i8] c"Error thrown in capping message\0A\00"
@.str.3 = [41 x i8] c"Error, timed out in sending message cap\0A\00"
define void @sendRawMsg(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8
store i8 10, i8* %4
%5 = icmp eq i8* %1, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ %7, %6 ], [ 0, %3 ]
%10 = icmp eq i8* %2, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %2)
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ %12, %11 ], [ 0, %8 ]
%15 = icmp sgt i32 %9, 0
br i1 %15, label %18, label %16
16: ; preds = %33, %13
%17 = icmp sgt i32 %14, 0
br i1 %17, label %35, label %52
18: ; preds = %13, %33
%19 = phi i32 [ %28, %33 ], [ 0, %13 ]
%20 = phi i32 [ %27, %33 ], [ 0, %13 ]
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = sub nsw i32 %9, %20
%24 = tail call i32 @send(i32 %0, i8* %22, i32 %23, i32 0)
%25 = icmp sgt i32 %24, 0
%26 = select i1 %25, i32 %24, i32 0
%27 = add nuw nsw i32 %26, %20
%28 = add nuw nsw i32 %19, 1
%29 = icmp ugt i32 %19, 100
br i1 %29, label %30, label %33
30: ; preds = %18
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %18
%34 = icmp sgt i32 %9, %27
br i1 %34, label %18, label %16
35: ; preds = %16, %50
%36 = phi i32 [ %45, %50 ], [ 0, %16 ]
%37 = phi i32 [ %44, %50 ], [ 0, %16 ]
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %2, i64 %38
%40 = sub nsw i32 %14, %37
%41 = tail call i32 @send(i32 %0, i8* %39, i32 %40, i32 0)
%42 = icmp sgt i32 %41, 0
%43 = select i1 %42, i32 %41, i32 0
%44 = add nuw nsw i32 %43, %37
%45 = add nuw nsw i32 %36, 1
%46 = icmp ugt i32 %36, 100
br i1 %46, label %47, label %50
47: ; preds = %35
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %47, %35
%51 = icmp sgt i32 %14, %44
br i1 %51, label %35, label %52
52: ; preds = %50, %16
br label %53
53: ; preds = %52, %66
%54 = phi i32 [ %61, %66 ], [ 0, %52 ]
%55 = call i32 @send(i32 %0, i8* %4, i32 1, i32 0)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %57, %53
%61 = add nuw nsw i32 %54, 1
%62 = icmp ugt i32 %54, 100
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %63, %60
%67 = icmp eq i32 %55, 0
br i1 %67, label %53, label %68
68: ; preds = %66
ret void
}