#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 */
scalar_t__ BackUpFile(char *, char *);
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ tokenize_input(char *, char **);
int write(int, char *, int);
int work(int sock, char *arr[], char *file_buffer) {
  int n, i, x;
  char buffer[4096], *path, *temp, no_buf[10];
  bzero(buffer, 4096);
  n = read(sock, buffer, 4096);
  if (n < 0)
    error("ERROR !! reading from socket");
  tokenize_input(buffer, arr);
  if ((strcmp(arr[0], "add")) == 0) {
    temp = malloc(sizeof(strlen("\nAddition = ")) + 10);
    x = atoi(arr[1]) + atoi(arr[2]);
    snprintf(no_buf, 10, "%d", x);
    strcpy(temp, no_buf);
    n = write(sock, temp, 50);
  } else if ((strcmp(arr[0], "mult")) == 0) {
    temp = malloc(sizeof(strlen("\nProduct = ")) + 10);
    x = atoi(arr[1]) * atoi(arr[2]);
    snprintf(no_buf, 10, "%d", x);
    strcpy(temp, no_buf);
    n = write(sock, temp, 50);
  } else if ((strcmp(arr[0], "BackUpFile")) == 0) {
    path = (char *)malloc(sizeof(strlen(arr[1])) + 1);
    path = (char *)arr[1];
    file_buffer = (char *)BackUpFile(path, file_buffer);
    n = write(sock, file_buffer, strlen(file_buffer) + 1);
  } else
    printf("\nService not Hosted by Server");
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1030(%rbp),%rdi
mov    $0x1000,%esi
call   10e0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1224 <work+0x54>
lea    0xde1(%rip),%rdi
call   10c0 <error@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <tokenize_input@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xddb(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d9 <work+0x109>
mov    $0xe,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1050(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ecx
mov    -0x1050(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
lea    -0x104a(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0xa,%esi
lea    0xd7c(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1040(%rbp),%rdi
lea    -0x104a(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x1040(%rbp),%rsi
mov    $0x32,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    1422 <work+0x252>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd3d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    137f <work+0x1af>
mov    $0xe,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1054(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ecx
mov    -0x1054(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
lea    -0x104a(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0xa,%esi
lea    0xcd6(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1040(%rbp),%rdi
lea    -0x104a(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x1040(%rbp),%rsi
mov    $0x32,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    141d <work+0x24d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xc9c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    140c <work+0x23c>
mov    $0x5,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <BackUpFile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1064(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1064(%rbp),%edi
mov    -0x1060(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    1418 <work+0x248>
lea    0xc21(%rip),%rdi
call   1060 <printf@plt>
jmp    141d <work+0x24d>
jmp    1422 <work+0x252>
mov    -0x4(%rbp),%eax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
call   10e0 <bzero@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
test   %eax,%eax
jns    1218 <work+0x48>
lea    0xded(%rip),%rdi
call   10c0 <error@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   10d0 <tokenize_input@plt>
mov    (%rbx),%rdi
lea    0xdee(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1276 <work+0xa6>
mov    (%rbx),%rdi
lea    0xde1(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     129b <work+0xcb>
mov    (%rbx),%rdi
lea    0xdd2(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12f2 <work+0x122>
lea    0xdc8(%rip),%rdi
call   1060 <printf@plt>
jmp    1317 <work+0x147>
mov    $0xe,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10f0 <atoi@plt>
add    %eax,%ebp
jmp    12bf <work+0xef>
mov    $0xe,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10f0 <atoi@plt>
imul   %eax,%ebp
lea    0xd5b(%rip),%rdx
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %ebp,%ecx
call   1070 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x32,%edx
jmp    1312 <work+0x142>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   10b0 <BackUpFile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"ERROR !! reading from socket\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"mult\00"
@.str.4 = [11 x i8] c"BackUpFile\00"
@.str.5 = [30 x i8] c"\0AService not Hosted by Server\00"
define i32 @work(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [10 x i8]
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%16 = call i32 @bzero(i8* %15, i32 4096)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 4096)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %3
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%26 = load i8**, i8*** %6
%27 = call i32 @tokenize_input(i8* %25, i8** %26)
%28 = load i8**, i8*** %6
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %53
33: ; preds = %24
%34 = call i8* @malloc(i32 14)
store i8* %34, i8** %13
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
%43 = add nsw i32 %38, %42
store i32 %43, i32* %10
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%45 = load i32, i32* %10
%46 = call i32 @snprintf(i8* %44, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %13
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%49 = call i32 @strcpy(i8* %47, i8* %48)
%50 = load i32, i32* %5
%51 = load i8*, i8** %13
%52 = call i32 @write(i32 %50, i8* %51, i32 50)
store i32 %52, i32* %8
br label %104
53: ; preds = %24
%54 = load i8**, i8*** %6
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %79
59: ; preds = %53
%60 = call i8* @malloc(i32 14)
store i8* %60, i8** %13
%61 = load i8**, i8*** %6
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
%65 = load i8**, i8*** %6
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
%69 = mul nsw i32 %64, %68
store i32 %69, i32* %10
%70 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%71 = load i32, i32* %10
%72 = call i32 @snprintf(i8* %70, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %71)
%73 = load i8*, i8** %13
%74 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%75 = call i32 @strcpy(i8* %73, i8* %74)
%76 = load i32, i32* %5
%77 = load i8*, i8** %13
%78 = call i32 @write(i32 %76, i8* %77, i32 50)
store i32 %78, i32* %8
br label %103
79: ; preds = %53
%80 = load i8**, i8*** %6
%81 = getelementptr inbounds i8*, i8** %80, i64 0
%82 = load i8*, i8** %81
%83 = call i64 @strcmp(i8* %82, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %100
85: ; preds = %79
%86 = call i8* @malloc(i32 5)
store i8* %86, i8** %12
%87 = load i8**, i8*** %6
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
store i8* %89, i8** %12
%90 = load i8*, i8** %12
%91 = load i8*, i8** %7
%92 = call i64 @BackUpFile(i8* %90, i8* %91)
%93 = inttoptr i64 %92 to i8*
store i8* %93, i8** %7
%94 = load i32, i32* %5
%95 = load i8*, i8** %7
%96 = load i8*, i8** %7
%97 = call i32 @strlen(i8* %96)
%98 = add nsw i32 %97, 1
%99 = call i32 @write(i32 %94, i8* %95, i32 %98)
store i32 %99, i32* %8
br label %102
100: ; preds = %79
%101 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %102
102: ; preds = %100, %85
br label %103
103: ; preds = %102, %59
br label %104
104: ; preds = %103, %33
%105 = load i32, i32* %4
ret i32 %105
}

LLVM IR (-O2):
@.str = [29 x i8] c"ERROR !! reading from socket\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"mult\00"
@.str.4 = [11 x i8] c"BackUpFile\00"
@.str.5 = [30 x i8] c"\0AService not Hosted by Server\00"
define i32 @work(i32 %0, i8** %1, i8* %2) {
%4 = alloca [4096 x i8]
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = call i32 @bzero(i8* %6, i32 4096)
%9 = call i32 @read(i32 %0, i8* %6, i32 4096)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = call i32 @tokenize_input(i8* %6, i8** %1)
%15 = load i8*, i8** %1
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = call dereferenceable_or_null(14) i8* @malloc(i32 14)
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = add nsw i32 %25, %22
%27 = call i32 @snprintf(i8* %7, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 @strcpy(i8* %19, i8* %7)
%29 = call i32 @write(i32 %0, i8* %19, i32 50)
br label %60
30: ; preds = %13
%31 = load i8*, i8** %1
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = call dereferenceable_or_null(14) i8* @malloc(i32 14)
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = mul nsw i32 %41, %38
%43 = call i32 @snprintf(i8* %7, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = call i32 @strcpy(i8* %35, i8* %7)
%45 = call i32 @write(i32 %0, i8* %35, i32 50)
br label %60
46: ; preds = %30
%47 = load i8*, i8** %1
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %46
%51 = getelementptr inbounds i8*, i8** %1, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @BackUpFile(i8* %52, i8* %2)
%54 = inttoptr i64 %53 to i8*
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i32 @write(i32 %0, i8* %54, i32 %56)
br label %60
58: ; preds = %46
%59 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %34, %58, %50, %18
ret i32 undef
}