#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*/ interrupt(int, int, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ neededSectors(int);
void editCommand(char *args[]) {
  char buffer[(32 - 6) * 512];
  char newBuffer[(32 - 6) * 512];
  char line[256];
  int buffcount;
  int oldbuffcount;
  int linecount;
  int flag;
  flag = 0;
  interrupt(0x21, 0x3, args[1], buffer, 0);
  buffcount = 0;
  oldbuffcount = 0;
  while (1) {
    linecount = 0;
    while (!(flag) && buffer[oldbuffcount] != '\r') {
      if (buffer[oldbuffcount] == '\0') {
        flag = 1;
        break;
      }
      line[linecount] = buffer[oldbuffcount];
      linecount++;
      oldbuffcount++;
    }
    line[linecount] = '\0';
    oldbuffcount += 2;
    interrupt(0x21, 0xc, line, 0, 0);
    if (line[0] == '\r') {
      newBuffer[buffcount] = '\0';
      buffcount++;
      break;
    }
    linecount = 0;
    while (line[linecount] != '\0') {
      newBuffer[buffcount] = line[linecount];
      linecount++;
      buffcount++;
    }
  }
  interrupt(0x21, 0x7, args[1], 0, 0);
  interrupt(0x21, 0x8, args[1], newBuffer, neededSectors(buffcount));
  return;
}


x86 assembly (clang, -O0):
<editCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6940,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x6920(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x3410(%rbp),%rcx
mov    $0x21,%edi
mov    $0x3,%esi
xor    %r8d,%r8d
call   1040 <interrupt@plt>
movl   $0x0,-0x6914(%rbp)
movl   $0x0,-0x6918(%rbp)
movl   $0x0,-0x691c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x6920(%rbp)
mov    %al,-0x6921(%rbp)
jne    11a8 <editCommand+0x88>
movslq -0x6918(%rbp),%rax
movsbl -0x3410(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
setne  %al
mov    %al,-0x6921(%rbp)
mov    -0x6921(%rbp),%al
test   $0x1,%al
jne    11bb <editCommand+0x9b>
jmp    1221 <editCommand+0x101>
movslq -0x6918(%rbp),%rax
movsbl -0x3410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11e2 <editCommand+0xc2>
movl   $0x1,-0x6920(%rbp)
jmp    1221 <editCommand+0x101>
movslq -0x6918(%rbp),%rax
mov    -0x3410(%rbp,%rax,1),%cl
movslq -0x691c(%rbp),%rax
mov    %cl,-0x6910(%rbp,%rax,1)
mov    -0x691c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x691c(%rbp)
mov    -0x6918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6918(%rbp)
jmp    1178 <editCommand+0x58>
movslq -0x691c(%rbp),%rax
movb   $0x0,-0x6910(%rbp,%rax,1)
mov    -0x6918(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x6918(%rbp)
lea    -0x6910(%rbp),%rdx
mov    $0x21,%edi
mov    $0xc,%esi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <interrupt@plt>
movsbl -0x6910(%rbp),%eax
cmp    $0xd,%eax
jne    128f <editCommand+0x16f>
movslq -0x6914(%rbp),%rax
movb   $0x0,-0x6810(%rbp,%rax,1)
mov    -0x6914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6914(%rbp)
jmp    12f5 <editCommand+0x1d5>
movl   $0x0,-0x691c(%rbp)
movslq -0x691c(%rbp),%rax
movsbl -0x6910(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     12f0 <editCommand+0x1d0>
movslq -0x691c(%rbp),%rax
mov    -0x6910(%rbp,%rax,1),%cl
movslq -0x6914(%rbp),%rax
mov    %cl,-0x6810(%rbp,%rax,1)
mov    -0x691c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x691c(%rbp)
mov    -0x6914(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6914(%rbp)
jmp    1299 <editCommand+0x179>
jmp    116e <editCommand+0x4e>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x21,%edi
mov    $0x7,%esi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1040 <interrupt@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x6938(%rbp)
lea    -0x6810(%rbp),%rax
mov    %rax,-0x6930(%rbp)
mov    -0x6914(%rbp),%edi
call   1030 <neededSectors@plt>
mov    -0x6938(%rbp),%rdx
mov    -0x6930(%rbp),%rcx
mov    %eax,%r8d
mov    $0x21,%edi
mov    $0x8,%esi
call   1040 <interrupt@plt>
add    $0x6940,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<editCommand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x6908,%rsp
mov    %rdi,%r14
mov    0x8(%rdi),%rdx
lea    0x3500(%rsp),%rcx
xor    %r12d,%r12d
mov    $0x21,%edi
mov    $0x3,%esi
xor    %r8d,%r8d
call   1040 <interrupt@plt>
mov    %rsp,%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1189 <editCommand+0x69>
xchg   %ax,%ax
xor    %eax,%eax
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
add    $0x2,%ebp
mov    $0x21,%edi
mov    $0xc,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <interrupt@plt>
mov    (%rsp),%al
test   %al,%al
jne    11d0 <editCommand+0xb0>
mov    %ebx,%eax
mov    $0x1,%ebx
test   %eax,%eax
jne    1160 <editCommand+0x40>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rcx
add    $0x3500,%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rcx,%rax,1),%edx
test   %dl,%dl
je     11c6 <editCommand+0xa6>
cmp    $0xd,%dl
je     11ca <editCommand+0xaa>
mov    %dl,(%rsp,%rax,1)
add    $0x1,%rax
jmp    11b0 <editCommand+0x90>
add    %eax,%ebp
jmp    1162 <editCommand+0x42>
add    %eax,%ebp
xor    %ebx,%ebx
jmp    1162 <editCommand+0x42>
movslq %r12d,%r13
cmp    $0xd,%al
je     1205 <editCommand+0xe5>
lea    (%rsp,%r13,1),%rdx
add    $0x100,%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %al,(%rdx,%rcx,1)
movzbl 0x1(%rsp,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    11f0 <editCommand+0xd0>
add    %ecx,%r12d
jmp    1189 <editCommand+0x69>
movb   $0x0,0x100(%rsp,%r13,1)
add    $0x1,%r13d
mov    0x8(%r14),%rdx
mov    $0x21,%edi
mov    $0x7,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <interrupt@plt>
mov    0x8(%r14),%r14
mov    %r13d,%edi
call   1030 <neededSectors@plt>
lea    0x100(%rsp),%rcx
mov    $0x21,%edi
mov    $0x8,%esi
mov    %r14,%rdx
mov    %eax,%r8d
call   1040 <interrupt@plt>
add    $0x6908,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @editCommand(i8** %0) {
%2 = alloca i8**
%3 = alloca [13312 x i8]
%4 = alloca [13312 x i8]
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %9
%10 = load i8**, i8*** %2
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 0
%14 = call i32 @interrupt(i32 33, i32 3, i8* %12, i8* %13, i32 0)
store i32 0, i32* %6
store i32 0, i32* %7
br label %15
15: ; preds = %1, %86
store i32 0, i32* %8
br label %16
16: ; preds = %36, %15
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 13
br label %26
26: ; preds = %19, %16
%27 = phi i1 [ false, %16 ], [ %25, %19 ]
br i1 %27, label %28, label %48
28: ; preds = %26
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 1, i32* %9
br label %48
36: ; preds = %28
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %42
store i8 %40, i8* %43
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %16
48: ; preds = %35, %26
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %50
store i8 0, i8* %51
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 2
store i32 %53, i32* %7
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%55 = call i32 @interrupt(i32 33, i32 12, i8* %54, i8* null, i32 0)
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 13
br i1 %59, label %60, label %66
60: ; preds = %48
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %87
66: ; preds = %48
store i32 0, i32* %8
br label %67
67: ; preds = %74, %66
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %86
74: ; preds = %67
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 %80
store i8 %78, i8* %81
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
%84 = load i32, i32* %6
%85 = add nsw i32 %84, 1
store i32 %85, i32* %6
br label %67
86: ; preds = %67
br label %15
87: ; preds = %60
%88 = load i8**, i8*** %2
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i32 @interrupt(i32 33, i32 7, i8* %90, i8* null, i32 0)
%92 = load i8**, i8*** %2
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = getelementptr inbounds [13312 x i8], [13312 x i8]* %4, i64 0, i64 0
%96 = load i32, i32* %6
%97 = call i32 @neededSectors(i32 %96)
%98 = call i32 @interrupt(i32 33, i32 8, i8* %94, i8* %95, i32 %97)
ret void
}

LLVM IR (-O2):
define void @editCommand(i8** nocapture %0) {
%2 = alloca [13312 x i8]
%3 = alloca [13312 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [13312 x i8], [13312 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %0, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @interrupt(i32 33, i32 3, i8* %9, i8* %5, i32 0)
br label %13
11: ; preds = %56
%12 = trunc i64 %62 to i32
br label %13
13: ; preds = %11, %1
%14 = phi i32 [ %12, %11 ], [ 0, %1 ]
%15 = phi i32 [ %42, %11 ], [ 0, %1 ]
%16 = phi i32 [ %39, %11 ], [ 0, %1 ]
br label %17
17: ; preds = %13, %36
%18 = phi i32 [ %42, %36 ], [ %15, %13 ]
%19 = phi i32 [ %39, %36 ], [ %16, %13 ]
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = sext i32 %18 to i64
br label %23
23: ; preds = %28, %21
%24 = phi i64 [ %22, %21 ], [ %31, %28 ]
%25 = phi i64 [ 0, %21 ], [ %30, %28 ]
%26 = getelementptr inbounds [13312 x i8], [13312 x i8]* %2, i64 0, i64 %24
%27 = load i8, i8* %26
switch i8 %27, label %28 [
i8 13, label %34
i8 0, label %32
]
28: ; preds = %23
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %25
store i8 %27, i8* %29
%30 = add nuw i64 %25, 1
%31 = add i64 %24, 1
br label %23
32: ; preds = %23
%33 = trunc i64 %24 to i32
br label %36
34: ; preds = %23
%35 = trunc i64 %24 to i32
br label %36
36: ; preds = %34, %17, %32
%37 = phi i32 [ %33, %32 ], [ %18, %17 ], [ %35, %34 ]
%38 = phi i64 [ %25, %32 ], [ 0, %17 ], [ %25, %34 ]
%39 = phi i32 [ 1, %32 ], [ 1, %17 ], [ 0, %34 ]
%40 = and i64 %38, 4294967295
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %40
store i8 0, i8* %41
%42 = add nsw i32 %37, 2
%43 = call i32 @interrupt(i32 33, i32 12, i8* %7, i8* null, i32 0)
%44 = load i8, i8* %7
switch i8 %44, label %45 [
i8 13, label %47
i8 0, label %17
]
45: ; preds = %36
%46 = sext i32 %14 to i64
br label %56
47: ; preds = %36
%48 = sext i32 %14 to i64
%49 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 %48
store i8 0, i8* %49
%50 = add nsw i32 %14, 1
%51 = load i8*, i8** %8
%52 = call i32 @interrupt(i32 33, i32 7, i8* %51, i8* null, i32 0)
%53 = load i8*, i8** %8
%54 = call i32 @neededSectors(i32 %50)
%55 = call i32 @interrupt(i32 33, i32 8, i8* %53, i8* %6, i32 %54)
ret void
56: ; preds = %45, %56
%57 = phi i64 [ %46, %45 ], [ %62, %56 ]
%58 = phi i64 [ 0, %45 ], [ %61, %56 ]
%59 = phi i8 [ %44, %45 ], [ %64, %56 ]
%60 = getelementptr inbounds [13312 x i8], [13312 x i8]* %3, i64 0, i64 %57
store i8 %59, i8* %60
%61 = add nuw nsw i64 %58, 1
%62 = add i64 %57, 1
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %61
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 0
br i1 %65, label %11, label %56
}