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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int server(int client_socket) {
  while (1) {
    int length;
    char *text;
    if (read(client_socket, &length, sizeof(length)) == 0)
      return 0;
    text = (char *)malloc(length);
    read(client_socket, text, length);
    printf("%s\n", text);
    free(text);
    if (!strcmp(text, "quit"))
      return 1;
  }
}


x86 assembly (clang, -O0):
<server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jne    1184 <server+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <server+0x94>
mov    -0xc(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    -0x18(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11df <server+0x8f>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <server+0x94>
jmp    115b <server+0xb>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xc(%rsp),%r14
lea    0xe96(%rip),%r15
lea    0xe93(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
je     11db <server+0x8b>
mov    0xc(%rsp),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <read@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1180 <server+0x30>
mov    $0x1,%eax
jmp    11dd <server+0x8d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"quit\00"
define i32 @server(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
br label %6
6: ; preds = %1, %27
%7 = load i32, i32* %3
%8 = call i64 (i32, ...) @read(i32 %7, i32* %4, i64 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6
store i32 0, i32* %2
br label %28
11: ; preds = %6
%12 = load i32, i32* %4
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
%15 = load i32, i32* %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %4
%18 = call i64 (i32, ...) @read(i32 %15, i8* %16, i32 %17)
%19 = load i8*, i8** %5
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %11
store i32 1, i32* %2
br label %28
27: ; preds = %11
br label %6
28: ; preds = %26, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"quit\00"
define i32 @server(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %8, %1
%5 = call i64 (i32, ...) @read(i32 %0, i32* %2, i64 4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %4
br label %18
8: ; preds = %4
%9 = load i32, i32* %2
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = load i32, i32* %2
%13 = call i64 (i32, ...) @read(i32 %0, i8* %11, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%15 = call i32 @free(i8* %11)
%16 = call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %4
18: ; preds = %8, %7
%19 = phi i32 [ 0, %7 ], [ 1, %8 ]
ret i32 %19
}