#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ readData(int, char *);
int /*<<< orphan*/ readMsg(int, char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ writeData(int, char *);
void doNormalMode(int socket) {
  char head[10 + 1], value[239 + 1];
  char fileBuffer[512 + 1];
  char fileChunk[512 - 20];
  char filename[256];
  long filesize;
  int fd;
  while (1) {
    readMsg(socket, head, value);
    if (!strcmp(head, "DEL")) {
      0;
      remove(value);
    } else if (!strcmp(head, "ADD")) {
      0;
      strcpy(filename, value);
      fd = open(filename, O_WRONLY | O_CREAT, 0644);
      readMsg(socket, head, fileChunk);
      while (1) {
        readData(socket, fileBuffer);
        if (!strcmp(fileBuffer, fileChunk))
          break;
        writeData(fd, fileBuffer);
      }
      close(fd);
      readMsg(socket, head, value);
    }
  }
}


x86 assembly (clang, -O0):
<doNormalMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
lea    -0x100(%rbp),%rdx
call   1080 <readMsg@plt>
lea    -0xf(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <doNormalMode+0x4b>
lea    -0x100(%rbp),%rdi
call   1030 <remove@plt>
jmp    129d <doNormalMode+0x11d>
lea    -0xf(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1298 <doNormalMode+0x118>
lea    -0x600(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x600(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,-0x60c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
lea    -0x500(%rbp),%rdx
call   1080 <readMsg@plt>
mov    -0x4(%rbp),%edi
lea    -0x310(%rbp),%rsi
call   1060 <readData@plt>
lea    -0x310(%rbp),%rdi
lea    -0x500(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1263 <doNormalMode+0xe3>
jmp    127a <doNormalMode+0xfa>
mov    -0x60c(%rbp),%edi
lea    -0x310(%rbp),%rsi
call   10a0 <writeData@plt>
jmp    1233 <doNormalMode+0xb3>
mov    -0x60c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%edi
lea    -0xf(%rbp),%rsi
lea    -0x100(%rbp),%rdx
call   1080 <readMsg@plt>
jmp    129d <doNormalMode+0x11d>
jmp    118e <doNormalMode+0xe>

x86 assembly (clang, -O2):
<doNormalMode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5f8,%rsp
mov    %edi,%ebx
lea    0x5(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0x200(%rsp),%r13
lea    0x3f0(%rsp),%rbp
jmp    11b8 <doNormalMode+0x38>
nop
mov    %r15,%rdi
call   1030 <remove@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <readMsg@plt>
cmpl   $0x4c4544,0x5(%rsp)
je     11b0 <doNormalMode+0x30>
cmpl   $0x444441,0x5(%rsp)
jne    11b8 <doNormalMode+0x38>
lea    0x100(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2dd4(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1080 <readMsg@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <readData@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1250 <doNormalMode+0xd0>
mov    %r12d,%edi
mov    %rbp,%rsi
call   10a0 <writeData@plt>
jmp    1220 <doNormalMode+0xa0>
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1050 <close@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <readMsg@plt>
jmp    11b8 <doNormalMode+0x38>

LLVM IR (-O0):
@.str = [4 x i8] c"DEL\00"
@.str.1 = [4 x i8] c"ADD\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @doNormalMode(i32 %0) {
%2 = alloca i32
%3 = alloca [11 x i8]
%4 = alloca [240 x i8]
%5 = alloca [513 x i8]
%6 = alloca [492 x i8]
%7 = alloca [256 x i8]
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %2
br label %10
10: ; preds = %1, %59
%11 = load i32, i32* %2
%12 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 0
%14 = call i32 @readMsg(i32 %11, i8* %12, i8* %13)
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 0
%20 = call i32 @remove(i8* %19)
br label %59
21: ; preds = %10
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %58, label %25
25: ; preds = %21
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 0
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* @O_WRONLY
%31 = load i32, i32* @O_CREAT
%32 = or i32 %30, %31
%33 = call i32 @open(i8* %29, i32 %32, i32 420)
store i32 %33, i32* %9
%34 = load i32, i32* %2
%35 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%36 = getelementptr inbounds [492 x i8], [492 x i8]* %6, i64 0, i64 0
%37 = call i32 @readMsg(i32 %34, i8* %35, i8* %36)
br label %38
38: ; preds = %25, %47
%39 = load i32, i32* %2
%40 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%41 = call i32 @readData(i32 %39, i8* %40)
%42 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%43 = getelementptr inbounds [492 x i8], [492 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcmp(i8* %42, i8* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %38
br label %51
47: ; preds = %38
%48 = load i32, i32* %9
%49 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%50 = call i32 @writeData(i32 %48, i8* %49)
br label %38
51: ; preds = %46
%52 = load i32, i32* %9
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %2
%55 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%56 = getelementptr inbounds [240 x i8], [240 x i8]* %4, i64 0, i64 0
%57 = call i32 @readMsg(i32 %54, i8* %55, i8* %56)
br label %58
58: ; preds = %51, %21
br label %59
59: ; preds = %58, %18
br label %10
}

LLVM IR (-O2):
@.str = [4 x i8] c"DEL\00"
@.str.1 = [4 x i8] c"ADD\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define void @doNormalMode(i32 %0) {
%2 = alloca [11 x i8]
%3 = alloca [240 x i8]
%4 = alloca [513 x i8]
%5 = alloca [492 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [240 x i8], [240 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [513 x i8], [513 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [492 x i8], [492 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %12
12: ; preds = %21, %1
%13 = call i32 @readMsg(i32 %0, i8* %7, i8* %8)
%14 = call i32 @bcmp(i8* dereferenceable(4) %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @remove(i8* %8)
br label %21
18: ; preds = %12
%19 = call i32 @bcmp(i8* dereferenceable(4) %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18, %37, %16
br label %12
22: ; preds = %18
%23 = call i32 @strcpy(i8* %11, i8* %8)
%24 = load i32, i32* @O_WRONLY
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = call i32 @open(i8* %11, i32 %26, i32 420)
%28 = call i32 @readMsg(i32 %0, i8* %7, i8* %10)
%29 = call i32 @readData(i32 %0, i8* %9)
%30 = call i32 @strcmp(i8* %9, i8* %10)
%31 = icmp eq i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %22, %32
%33 = call i32 @writeData(i32 %27, i8* %9)
%34 = call i32 @readData(i32 %0, i8* %9)
%35 = call i32 @strcmp(i8* %9, i8* %10)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %32
37: ; preds = %32, %22
%38 = call i32 @close(i32 %27)
%39 = call i32 @readMsg(i32 %0, i8* %7, i8* %8)
br label %21
}