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

/* Variables and functions */
scalar_t__ lw_sock_send_str(int *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ recv_ok(int *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int, char *);
int lw_protocol_reserve_team(int *sock, int num, int control_type, char *name) {
  int result = 0;
  char message[1000];
  {
    {
      memset(((message)), 0, (sizeof(message)));
      snprintf(((message)), (sizeof(message)) - 1, (("%s %d,%d,'%s'")),
               (("TEAM")), ((num)), (control_type), ((name)));
      ((message))[(sizeof(message)) - 1] = '\0';
    };
  };
  if (*sock >= 0 && lw_sock_send_str(sock, message)) {
    if (recv_ok(sock)) {
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<lw_protocol_reserve_team>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x18(%rbp),%rax
mov    $0x3e7,%esi
lea    0xe6e(%rip),%rdx
lea    0xe75(%rip),%rcx
mov    %rax,(%rsp)
call   1040 <snprintf@plt>
movb   $0x0,-0x29(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11ec <lw_protocol_reserve_team+0xac>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1060 <lw_sock_send_str@plt>
cmp    $0x0,%rax
je     11ec <lw_protocol_reserve_team+0xac>
mov    -0x8(%rbp),%rdi
call   1030 <recv_ok@plt>
cmp    $0x0,%rax
je     11e7 <lw_protocol_reserve_team+0xa7>
movl   $0x1,-0x1c(%rbp)
jmp    11ec <lw_protocol_reserve_team+0xac>
mov    -0x1c(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lw_protocol_reserve_team>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
mov    %rbp,(%rsp)
lea    0xe81(%rip),%rdx
lea    0xe88(%rip),%rcx
mov    %r13,%rdi
mov    $0x3e7,%esi
mov    %r12d,%r8d
mov    %r15d,%r9d
call   1040 <snprintf@plt>
movb   $0x0,0x3f7(%rsp)
cmpl   $0x0,(%rbx)
js     11ca <lw_protocol_reserve_team+0x8a>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <lw_sock_send_str@plt>
test   %rax,%rax
je     11ca <lw_protocol_reserve_team+0x8a>
mov    %rbx,%rdi
call   1030 <recv_ok@plt>
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    %r14d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%s %d,%d,'%s'\00"
@.str.1 = [5 x i8] c"TEAM\00"
define i32 @lw_protocol_reserve_team(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1000 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1000)
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = load i8*, i8** %8
%17 = call i32 @snprintf(i8* %13, i32 999, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i8* %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 999
store i8 0, i8* %18
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %4
%23 = load i32*, i32** %5
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%25 = call i64 @lw_sock_send_str(i32* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32*, i32** %5
%29 = call i64 @recv_ok(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %9
br label %32
32: ; preds = %31, %27
br label %33
33: ; preds = %32, %22, %4
%34 = load i32, i32* %9
ret i32 %34
}

LLVM IR (-O2):
@.str = [14 x i8] c"%s %d,%d,'%s'\00"
@.str.1 = [5 x i8] c"TEAM\00"
define i32 @lw_protocol_reserve_team(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [1000 x i8]
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 1000)
%8 = call i32 @snprintf(i8* %6, i32 999, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2, i8* %3)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 999
store i8 0, i8* %9
%10 = load i32, i32* %0
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %4
%13 = call i64 @lw_sock_send_str(i32* %0, i8* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = call i64 @recv_ok(i32* %0)
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %12, %4
%20 = phi i32 [ 0, %12 ], [ 0, %4 ], [ %18, %15 ]
ret i32 %20
}