#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*/ path;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ executeCommand(char *, char *);
int /*<<< orphan*/ getcwd(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int write(int, char *, int);
void processChild(int sockfd) {
  FILE *fp;
  int status;
  char path[1024];
  int n;
  char buf[1024];
  char buffer[1024];
  char buffer2[1024];
  char exitTest[1024] = "exit";
  getcwd(path, sizeof(path));
  strcat(path, "$ ");
  write(sockfd, path, 1024);
  while ((n = read(sockfd, buf, 1024)) > 0) {
    getcwd(path, sizeof(path));
    strncpy(buffer, buf, strlen(buf) - 2);
    if (strcmp(buffer, exitTest) == 0)
      break;
    executeCommand(buffer, buffer2);
    strcat(path, "$ ");
    strcat(path, buffer2);
    n = write(sockfd, path, 1024);
    bzero(path, 1024);
    bzero(buf, 1024);
    bzero(buffer, 1024);
    bzero(buffer2, 1024);
  }
}


x86 assembly (clang, -O0):
<processChild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1440,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x1430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movb   $0x65,-0x1430(%rbp)
movb   $0x78,-0x142f(%rbp)
movb   $0x69,-0x142e(%rbp)
movb   $0x74,-0x142d(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
lea    -0x420(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    1349 <processChild+0x1a9>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
lea    -0xc30(%rbp),%rax
mov    %rax,-0x1440(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x1438(%rbp)
lea    -0x830(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1440(%rbp),%rdi
mov    -0x1438(%rbp),%rsi
mov    %rax,%rdx
sub    $0x2,%rdx
call   1030 <strncpy@plt>
lea    -0xc30(%rbp),%rdi
lea    -0x1430(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12ad <processChild+0x10d>
jmp    1349 <processChild+0x1a9>
lea    -0xc30(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
call   1040 <executeCommand@plt>
lea    -0x420(%rbp),%rdi
lea    0xd32(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x420(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
lea    -0x830(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
lea    -0xc30(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
lea    -0x1030(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
jmp    1215 <processChild+0x75>
add    $0x1440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processChild>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1408,%rsp
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
movl   $0x74697865,(%rsp)
lea    0x800(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
lea    0x400(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    12f9 <processChild+0x159>
lea    0x800(%rsp),%rbx
lea    0x400(%rsp),%r15
lea    0x1000(%rsp),%rbp
mov    %rsp,%r12
lea    0xc00(%rsp),%r13
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    -0x2(%rax),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12f9 <processChild+0x159>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <executeCommand@plt>
mov    %rbx,%rdi
lea    0xd73(%rip),%rsi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <strcat@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    %r15,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    %r13,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     1240 <processChild+0xa0>
add    $0x1408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"$ \00"
define void @processChild(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
store i32 %0, i32* %2
%11 = bitcast [1024 x i8]* %10 to i8*
%12 = bitcast i8* %11 to [1024 x i8]*
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i32 0, i32 0
store i8 101, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i32 0, i32 1
store i8 120, i8* %14
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i32 0, i32 2
store i8 105, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i32 0, i32 3
store i8 116, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @getcwd(i8* %17, i32 1024)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @write(i32 %21, i8* %22, i32 1024)
br label %24
24: ; preds = %43, %1
%25 = load i32, i32* %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 1024)
store i32 %27, i32* %6
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %63
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = call i32 @getcwd(i8* %30, i32 1024)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = call i64 @strlen(i8* %34)
%36 = sub nsw i64 %35, 2
%37 = call i32 @strncpy(i8* %32, i8* %33, i64 %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%40 = call i64 @strcmp(i8* %38, i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %29
br label %63
43: ; preds = %29
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%46 = call i32 @executeCommand(i8* %44, i8* %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%51 = call i32 @strcat(i8* %49, i8* %50)
%52 = load i32, i32* %2
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%54 = call i32 @write(i32 %52, i8* %53, i32 1024)
store i32 %54, i32* %6
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%56 = call i32 @bzero(i8* %55, i32 1024)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = call i32 @bzero(i8* %57, i32 1024)
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%60 = call i32 @bzero(i8* %59, i32 1024)
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = call i32 @bzero(i8* %61, i32 1024)
br label %24
63: ; preds = %42, %24
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"$ \00"
define void @processChild(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 101, i8* %11
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1
store i8 120, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 2
store i8 105, i8* %13
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 3
store i8 116, i8* %14
%15 = call i32 @getcwd(i8* %7, i32 1024)
%16 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @write(i32 %0, i8* %7, i32 1024)
%18 = call i32 @read(i32 %0, i8* %8, i32 1024)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %1, %27
%21 = call i32 @getcwd(i8* %7, i32 1024)
%22 = call i64 @strlen(i8* %8)
%23 = add nsw i64 %22, -2
%24 = call i32 @strncpy(i8* %9, i8* %8, i64 %23)
%25 = call i64 @strcmp(i8* %9, i8* %11)
%26 = icmp eq i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %20
%28 = call i32 @executeCommand(i8* %9, i8* %10)
%29 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @strcat(i8* %7, i8* %10)
%31 = call i32 @write(i32 %0, i8* %7, i32 1024)
%32 = call i32 @bzero(i8* %7, i32 1024)
%33 = call i32 @bzero(i8* %8, i32 1024)
%34 = call i32 @bzero(i8* %9, i32 1024)
%35 = call i32 @bzero(i8* %10, i32 1024)
%36 = call i32 @read(i32 %0, i8* %8, i32 1024)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %20, label %38
38: ; preds = %27, %20, %1
ret void
}