#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*/ free(char *);
int read_net(int, char **);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, ...);
int get_message(int network, int outgoing) {
  char *buffer = 0;
  char size[10];
  int len = read_net(network, &buffer);
  if (len == 0)
    return 0;
  if (len == -1) {
    write(outgoing, "-1;", 3);
    return -1;
  }
  sprintf(size, "%d;", len);
  write(outgoing, &size, strlen(size));
  write(outgoing, buffer, len);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<get_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <read_net@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    118b <get_message+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    120a <get_message+0xba>
cmpl   $0xffffffff,-0x28(%rbp)
jne    11b7 <get_message+0x67>
mov    -0xc(%rbp),%edi
lea    0xe61(%rip),%rsi
mov    $0x3,%edx
mov    $0x0,%al
call   1040 <write@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <get_message+0xba>
lea    -0x22(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe3f(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x22(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    -0x22(%rbp),%rsi
mov    $0x0,%al
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_message>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1060 <read_net@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11dc <get_message+0x8c>
cmp    $0xffffffff,%ebp
jne    1194 <get_message+0x44>
lea    0xe81(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    $0xffffffff,%ebp
jmp    11dc <get_message+0x8c>
lea    0xe69(%rip),%rsi
lea    0x16(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-1;\00"
@.str.1 = [4 x i8] c"%d;\00"
define i32 @get_message(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [10 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* null, i8** %6
%9 = load i32, i32* %4
%10 = call i32 @read_net(i32 %9, i8** %6)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %34
14: ; preds = %2
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %5
%19 = call i32 (i32, ...) @write(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
store i32 -1, i32* %3
br label %34
20: ; preds = %14
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* %8
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %5
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 (i32, ...) @write(i32 %24, [10 x i8]* %7, i32 %26)
%28 = load i32, i32* %5
%29 = load i8*, i8** %6
%30 = load i32, i32* %8
%31 = call i32 (i32, ...) @write(i32 %28, i8* %29, i32 %30)
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
store i32 0, i32* %3
br label %34
34: ; preds = %20, %17, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [4 x i8] c"-1;\00"
@.str.1 = [4 x i8] c"%d;\00"
define i32 @get_message(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = call i32 @read_net(i32 %0, i8** %3)
switch i32 %7, label %10 [
i32 0, label %18
i32 -1, label %8
]
8: ; preds = %2
%9 = call i32 (i32, ...) @write(i32 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
br label %18
10: ; preds = %2
%11 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%12 = call i32 @strlen(i8* %6)
%13 = call i32 (i32, ...) @write(i32 %1, [10 x i8]* %4, i32 %12)
%14 = load i8*, i8** %3
%15 = call i32 (i32, ...) @write(i32 %1, i8* %14, i32 %7)
%16 = load i8*, i8** %3
%17 = call i32 @free(i8* %16)
br label %18
18: ; preds = %2, %10, %8
%19 = phi i32 [ -1, %8 ], [ 0, %10 ], [ %7, %2 ]
ret i32 %19
}