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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ calloc(int, int);
int read(int, char *, int);
int write_net(int, char *, int);
int send_message(int incoming, int network) {
  char size[10];
  char ch;
  char *ptr = size, *buffer = 0;
  int ret, len;
  bzero(size, sizeof(size));
  ret = read(incoming, &ch, 1);
  while (1) {
    if (ret <= 0)
      return -1;
    if (ch == ';')
      break;
    *ptr++ = ch;
    ret = read(incoming, &ch, 1);
  }
  len = atoi(size);
  if (len == 0)
    return 0;
  if (len == -1)
    return -1;
  buffer = (char *)calloc(len + 1, 1);
  ret = read(incoming, buffer, len);
  if (ret < 0)
    return -1;
  ret = write_net(network, buffer, len);
  return (ret == len) ? 0 : -1;
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x16(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x16(%rbp),%rdi
mov    $0xa,%esi
call   1060 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     11a6 <send_message+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    1280 <send_message+0x130>
movsbl -0x17(%rbp),%eax
cmp    $0x3b,%eax
jne    11b8 <send_message+0x68>
jmp    11e5 <send_message+0x95>
mov    -0x17(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x2c(%rbp)
jmp    1190 <send_message+0x40>
lea    -0x16(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    1207 <send_message+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    1280 <send_message+0x130>
cmpl   $0xffffffff,-0x30(%rbp)
jne    121d <send_message+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1280 <send_message+0x130>
mov    -0x30(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1259 <send_message+0x109>
movl   $0xffffffff,-0x4(%rbp)
jmp    1280 <send_message+0x130>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1050 <write_net@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%esi
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x6(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1060 <bzero@plt>
lea    0x5(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
mov    $0xffffffff,%r15d
test   %eax,%eax
jle    1218 <send_message+0xc8>
lea    0x5(%rsp),%r12
nopw   0x0(%rax,%rax,1)
movzbl 0x5(%rsp),%eax
cmp    $0x3b,%al
je     11c5 <send_message+0x75>
mov    %al,0x0(%rbp)
add    $0x1,%rbp
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jg     11a0 <send_message+0x50>
jmp    1218 <send_message+0xc8>
lea    0x6(%rsp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1215 <send_message+0xc5>
cmp    $0xffffffff,%ebp
je     1218 <send_message+0xc8>
lea    0x1(%rbp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
js     1218 <send_message+0xc8>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <write_net@plt>
xor    %r15d,%r15d
cmp    %ebp,%eax
setne  %r15b
neg    %r15d
jmp    1218 <send_message+0xc8>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_message(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %8
store i8* null, i8** %9
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 10)
%15 = load i32, i32* %4
%16 = call i32 @read(i32 %15, i8* %7, i32 1)
store i32 %16, i32* %10
br label %17
17: ; preds = %2, %26
%18 = load i32, i32* %10
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %3
br label %64
21: ; preds = %17
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 59
br i1 %24, label %25, label %26
25: ; preds = %21
br label %32
26: ; preds = %21
%27 = load i8, i8* %7
%28 = load i8*, i8** %8
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %8
store i8 %27, i8* %28
%30 = load i32, i32* %4
%31 = call i32 @read(i32 %30, i8* %7, i32 1)
store i32 %31, i32* %10
br label %17
32: ; preds = %25
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 0, i32* %3
br label %64
38: ; preds = %32
%39 = load i32, i32* %11
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 -1, i32* %3
br label %64
42: ; preds = %38
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
%45 = call i64 @calloc(i32 %44, i32 1)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %9
%47 = load i32, i32* %4
%48 = load i8*, i8** %9
%49 = load i32, i32* %11
%50 = call i32 @read(i32 %47, i8* %48, i32 %49)
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %42
store i32 -1, i32* %3
br label %64
54: ; preds = %42
%55 = load i32, i32* %5
%56 = load i8*, i8** %9
%57 = load i32, i32* %11
%58 = call i32 @write_net(i32 %55, i8* %56, i32 %57)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = icmp eq i32 %59, %60
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 0, i32 -1
store i32 %63, i32* %3
br label %64
64: ; preds = %54, %53, %41, %37, %20
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
define i32 @send_message(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 10)
%7 = call i32 @read(i32 %0, i8* %4, i32 1)
%8 = icmp slt i32 %7, 1
br i1 %8, label %30, label %9
9: ; preds = %2, %13
%10 = phi i8* [ %14, %13 ], [ %5, %2 ]
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 59
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %11, i8* %10
%15 = call i32 @read(i32 %0, i8* %4, i32 1)
%16 = icmp slt i32 %15, 1
br i1 %16, label %30, label %9
17: ; preds = %9
%18 = call i32 @atoi(i8* %5)
switch i32 %18, label %20 [
i32 0, label %30
i32 -1, label %19
]
19: ; preds = %17
br label %30
20: ; preds = %17
%21 = add nuw nsw i32 %18, 1
%22 = tail call i64 @calloc(i32 %21, i32 1)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @read(i32 %0, i8* %23, i32 %18)
%25 = icmp slt i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = tail call i32 @write_net(i32 %1, i8* %23, i32 %18)
%28 = icmp ne i32 %27, %18
%29 = sext i1 %28 to i32
br label %30
30: ; preds = %13, %2, %20, %17, %26, %19
%31 = phi i32 [ -1, %19 ], [ %29, %26 ], [ %18, %17 ], [ -1, %20 ], [ -1, %2 ], [ -1, %13 ]
ret i32 %31
}