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

/* Variables and functions */
int /*<<< orphan*/ packet_disp_err(int);
int packet_pack_word_req(char *, char *);
int packet_unpack_word_resp(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int recv_packet(int, char *);
int send_fix_len(int, char *, int);
int /*<<< orphan*/ word_input(char *, int);
int do_word(int sockfd) {
  int ret = 0;
  char word[512];
  char packet[1024];
  char explain[1024];
  word_input(word, sizeof(word));
  if ('1' == word[0] && '\0' == word[1]) {
    ret = 2;
    goto exit;
  }
  ret = packet_pack_word_req(packet, word);
  ret = send_fix_len(sockfd, packet, ret);
  if (-1 == ret) {
    goto exit;
  }
  ret = recv_packet(sockfd, packet);
  if (ret <= 0) {
    goto exit;
  }
  ret = packet_unpack_word_resp(packet, explain);
  if (0 == ret) {
    printf("%s\n", explain);
  } else {
    packet_disp_err(ret);
  }
  ret = 1;
exit:
  return ret;
}


x86 assembly (clang, -O0):
<do_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1090 <word_input@plt>
movsbl -0x210(%rbp),%ecx
mov    $0x31,%eax
cmp    %ecx,%eax
jne    11c7 <do_word+0x57>
movsbl -0x20f(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11c7 <do_word+0x57>
movl   $0x2,-0x8(%rbp)
jmp    126e <do_word+0xfe>
lea    -0x610(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1060 <packet_pack_word_req@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x610(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <send_fix_len@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1205 <do_word+0x95>
jmp    126e <do_word+0xfe>
mov    -0x4(%rbp),%edi
lea    -0x610(%rbp),%rsi
call   1080 <recv_packet@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1226 <do_word+0xb6>
jmp    126e <do_word+0xfe>
lea    -0x610(%rbp),%rdi
lea    -0xa10(%rbp),%rsi
call   1050 <packet_unpack_word_resp@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    125f <do_word+0xef>
lea    -0xa10(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
jmp    1267 <do_word+0xf7>
mov    -0x8(%rbp),%edi
call   1070 <packet_disp_err@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xa10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_word>:
push   %r14
push   %rbx
sub    $0xa08,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x200,%esi
call   1090 <word_input@plt>
cmpb   $0x31,(%rsp)
jne    119b <do_word+0x2b>
mov    $0x2,%eax
cmpb   $0x0,0x1(%rsp)
je     1214 <do_word+0xa4>
lea    0x200(%rsp),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
call   1060 <packet_pack_word_req@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <send_fix_len@plt>
cmp    $0xffffffff,%eax
je     11f4 <do_word+0x84>
lea    0x200(%rsp),%rsi
mov    %ebx,%edi
call   1080 <recv_packet@plt>
test   %eax,%eax
jle    1214 <do_word+0xa4>
lea    0x200(%rsp),%rdi
lea    0x600(%rsp),%rsi
call   1050 <packet_unpack_word_resp@plt>
test   %eax,%eax
je     11fb <do_word+0x8b>
mov    %eax,%edi
call   1070 <packet_disp_err@plt>
jmp    120f <do_word+0x9f>
mov    $0xffffffff,%eax
jmp    1214 <do_word+0xa4>
lea    0xdfe(%rip),%rdi
lea    0x600(%rsp),%rsi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0xa08,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @do_word(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = call i32 @word_input(i8* %7, i32 512)
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 49, %11
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 0, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 2, i32* %3
br label %50
19: ; preds = %13, %1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%22 = call i32 @packet_pack_word_req(i8* %20, i8* %21)
store i32 %22, i32* %3
%23 = load i32, i32* %2
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @send_fix_len(i32 %23, i8* %24, i32 %25)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp eq i32 -1, %27
br i1 %28, label %29, label %30
29: ; preds = %19
br label %50
30: ; preds = %19
%31 = load i32, i32* %2
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%33 = call i32 @recv_packet(i32 %31, i8* %32)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
br label %50
37: ; preds = %30
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = call i32 @packet_unpack_word_resp(i8* %38, i8* %39)
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = icmp eq i32 0, %41
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %44)
br label %49
46: ; preds = %37
%47 = load i32, i32* %3
%48 = call i32 @packet_disp_err(i32 %47)
br label %49
49: ; preds = %46, %43
store i32 1, i32* %3
br label %50
50: ; preds = %49, %36, %29, %18
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @do_word(i32 %0) {
%2 = alloca [512 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @word_input(i8* %5, i32 512)
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 49
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %29, label %15
15: ; preds = %1
%16 = call i32 @packet_pack_word_req(i8* %6, i8* %5)
%17 = call i32 @send_fix_len(i32 %0, i8* %6, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = call i32 @recv_packet(i32 %0, i8* %6)
%21 = icmp slt i32 %20, 1
br i1 %21, label %29, label %22
22: ; preds = %19
%23 = call i32 @packet_unpack_word_resp(i8* %6, i8* %7)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %29
27: ; preds = %22
%28 = call i32 @packet_disp_err(i32 %23)
br label %29
29: ; preds = %25, %27, %1, %19, %15
%30 = phi i32 [ -1, %15 ], [ %20, %19 ], [ 2, %1 ], [ 1, %27 ], [ 1, %25 ]
ret i32 %30
}