#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*/ bzero(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int ntohl(unsigned int);
int /*<<< orphan*/ read_(int, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
void function(int socket) {
  char string[128];
  char buffer4[4];
  unsigned int size;
  bzero(buffer4, 4);
  bzero(string, 128);
  read_(socket, buffer4, 4);
  if (strncmp(buffer4, "QUES", strlen("QUES")) != 0) {
    fprintf(stdout, "ERROR:BAD_HEADER\n");
    return;
  }
  size = 0;
  read_(socket, &size, 4);
  size = ntohl(size);
  fprintf(stdout, "SIZE:%d\n", size);
  read_(socket, string, size);
  bzero(buffer4, 4);
  read_(socket, buffer4, 4);
  if (strncmp(buffer4, "END\n", strlen("END\n")) != 0) {
    fprintf(stdout, "ERROR:BAD_ENDER\n");
    return;
  }
  fprintf(stdout, "OK\n");
}


x86 assembly (clang, -O0):
<function>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x94(%rbp),%rdi
mov    $0x4,%esi
call   1060 <bzero@plt>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1060 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x94(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <read_@plt>
lea    -0x94(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    0xe45(%rip),%rdi
call   1040 <strlen@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%edx
lea    0xe30(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11fb <function+0x9b>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12f3 <function+0x193>
movl   $0x0,-0x98(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x98(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <read_@plt>
mov    -0x98(%rbp),%edi
call   1080 <ntohl@plt>
mov    %eax,-0x98(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x98(%rbp),%edx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x98(%rbp),%edx
mov    $0x0,%al
call   1070 <read_@plt>
lea    -0x94(%rbp),%rdi
mov    $0x4,%esi
call   1060 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x94(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <read_@plt>
lea    -0x94(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    0xd84(%rip),%rdi
call   1040 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%edx
lea    0xd6f(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12dc <function+0x17c>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12f3 <function+0x193>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<function>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %edi,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <bzero@plt>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
call   1060 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <read_@plt>
lea    0xe56(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11d9 <function+0x79>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
jmp    1287 <function+0x127>
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <read_@plt>
mov    0x8(%rsp),%edi
call   1080 <ntohl@plt>
mov    %eax,0x8(%rsp)
mov    0x2dd7(%rip),%r15
mov    (%r15),%edi
lea    0xe04(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
xor    %eax,%eax
call   1070 <read_@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <read_@plt>
lea    0xdc6(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    (%r15),%edi
test   %rax,%rax
je     1280 <function+0x120>
lea    0xda7(%rip),%rsi
jmp    1287 <function+0x127>
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"QUES\00"
@stdout = global i32 0
@.str.1 = [18 x i8] c"ERROR:BAD_HEADER\0A\00"
@.str.2 = [9 x i8] c"SIZE:%d\0A\00"
@.str.3 = [5 x i8] c"END\0A\00"
@.str.4 = [17 x i8] c"ERROR:BAD_ENDER\0A\00"
@.str.5 = [4 x i8] c"OK\0A\00"
define void @function(i32 %0) {
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca [4 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 4)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i32 128)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%12 = call i32 (i32, ...) @read_(i32 %10, i8* %11, i32 4)
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @stdout
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %47
20: ; preds = %1
store i32 0, i32* %5
%21 = load i32, i32* %2
%22 = call i32 (i32, ...) @read_(i32 %21, i32* %5, i32 4)
%23 = load i32, i32* %5
%24 = call i32 @ntohl(i32 %23)
store i32 %24, i32* %5
%25 = load i32, i32* @stdout
%26 = load i32, i32* %5
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %2
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 (i32, ...) @read_(i32 %28, i8* %29, i32 %30)
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%33 = call i32 @bzero(i8* %32, i32 4)
%34 = load i32, i32* %2
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%36 = call i32 (i32, ...) @read_(i32 %34, i8* %35, i32 4)
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%38 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %20
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %47
44: ; preds = %20
%45 = load i32, i32* @stdout
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %44, %41, %17
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"QUES\00"
@stdout = global i32 0
@.str.1 = [18 x i8] c"ERROR:BAD_HEADER\0A\00"
@.str.2 = [9 x i8] c"SIZE:%d\0A\00"
@.str.3 = [5 x i8] c"END\0A\00"
@.str.4 = [17 x i8] c"ERROR:BAD_ENDER\0A\00"
@.str.5 = [4 x i8] c"OK\0A\00"
define void @function(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = call i32 @bzero(i8* %6, i32 4)
%9 = call i32 @bzero(i8* %5, i32 128)
%10 = call i32 (i32, ...) @read_(i32 %0, i8* %6, i32 4)
%11 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %35
17: ; preds = %1
store i32 0, i32* %4
%18 = call i32 (i32, ...) @read_(i32 %0, i32* %4, i32 4)
%19 = load i32, i32* %4
%20 = call i32 @ntohl(i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%23 = load i32, i32* %4
%24 = call i32 (i32, ...) @read_(i32 %0, i8* %5, i32 %23)
%25 = call i32 @bzero(i8* %6, i32 4)
%26 = call i32 (i32, ...) @read_(i32 %0, i8* %6, i32 4)
%27 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = icmp eq i64 %28, 0
%30 = load i32, i32* @stdout
br i1 %29, label %33, label %31
31: ; preds = %17
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %35
33: ; preds = %17
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %14
ret void
}