#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 atoi(char *const);
int /*<<< orphan*/ commit_kit(char *);
int /*<<< orphan*/ escape_dq(char *);
int /*<<< orphan*/ gen_arg_str(int, char *const *, int, char *);
int getopt(int, char *const *, char *);
scalar_t__ is_num(char *const);
int optind;
int read_kit_file(int, char **);
int /*<<< orphan*/ save_kit_file(int, char **);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void cmd_edit(int argc, char *const argv[]) {
  char buffer[128][128] = {{0}};
  char mes[128] = "[kit]edit plan to ";
  char opt[128];
  int i, num, pointer, n_opt = 0;
  if (getopt(argc, argv, "n") != -1) {
    n_opt = 1;
  }
  num = read_kit_file(127, buffer);
  if ((optind < argc) && (is_num(argv[optind]) == 0)) {
    pointer = atoi(argv[optind]);
    optind++;
  } else {
    pointer = 0;
  }
  gen_arg_str(argc, argv, optind, opt);
  strcpy(buffer[pointer], opt);
  save_kit_file(num, buffer);
  if (n_opt == 0) {
    escape_dq(opt);
    strcat(mes, opt);
    commit_kit(mes);
  }
}


x86 assembly (clang, -O0):
<cmd_edit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x4010(%rbp),%rdi
xor    %esi,%esi
mov    $0x4000,%edx
call   1060 <memset@plt>
lea    -0x4090(%rbp),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x80,%edx
call   1080 <memcpy@plt>
movl   $0x0,-0x4120(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   10c0 <getopt@plt>
cmp    $0xffffffff,%eax
je     122d <cmd_edit+0x6d>
movl   $0x1,-0x4120(%rbp)
lea    -0x4010(%rbp),%rsi
mov    $0x7f,%edi
call   1070 <read_kit_file@plt>
mov    %eax,-0x4118(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jge    12ae <cmd_edit+0xee>
mov    -0x10(%rbp),%rax
mov    0x2d87(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <is_num@plt>
cmp    $0x0,%rax
jne    12ae <cmd_edit+0xee>
mov    -0x10(%rbp),%rax
mov    0x2d66(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x411c(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d41(%rip),%rax
mov    %ecx,(%rax)
jmp    12b8 <cmd_edit+0xf8>
movl   $0x0,-0x411c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
lea    -0x4110(%rbp),%rcx
call   1040 <gen_arg_str@plt>
movslq -0x411c(%rbp),%rax
lea    -0x4010(%rbp),%rdi
shl    $0x7,%rax
add    %rax,%rdi
lea    -0x4110(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4118(%rbp),%edi
lea    -0x4010(%rbp),%rsi
call   10b0 <save_kit_file@plt>
cmpl   $0x0,-0x4120(%rbp)
jne    133f <cmd_edit+0x17f>
lea    -0x4110(%rbp),%rdi
call   1050 <escape_dq@plt>
lea    -0x4090(%rbp),%rdi
lea    -0x4110(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x4090(%rbp),%rdi
call   1090 <commit_kit@plt>
add    $0x4120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_edit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4118,%rsp
mov    %rsi,%r12
mov    %edi,%r13d
lea    0x110(%rsp),%rbx
xor    %r14d,%r14d
mov    $0x4000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe4d(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe31(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe15(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdf9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xddd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xdc1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe35(%rip),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   10b0 <getopt@plt>
mov    %eax,0xc(%rsp)
mov    $0x7f,%edi
mov    %rbx,%rsi
call   1070 <read_kit_file@plt>
mov    %eax,%r15d
mov    0x2d77(%rip),%rbp
mov    0x0(%rbp),%ebx
cmp    %r13d,%ebx
jge    12a7 <cmd_edit+0xf7>
movslq %ebx,%rax
mov    (%r12,%rax,8),%rdi
call   1090 <is_num@plt>
mov    0x0(%rbp),%ebx
test   %rax,%rax
je     1292 <cmd_edit+0xe2>
xor    %r14d,%r14d
jmp    12a7 <cmd_edit+0xf7>
movslq %ebx,%rbx
mov    (%r12,%rbx,8),%rdi
call   10c0 <atoi@plt>
add    $0x1,%ebx
mov    %ebx,0x0(%rbp)
movslq %eax,%r14
lea    0x90(%rsp),%rbp
mov    %r13d,%edi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %rbp,%rcx
call   1040 <gen_arg_str@plt>
shl    $0x7,%r14
lea    (%rsp,%r14,1),%rdi
add    $0x110,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0x110(%rsp),%rsi
mov    %r15d,%edi
call   10a0 <save_kit_file@plt>
cmpl   $0xffffffff,0xc(%rsp)
jne    1315 <cmd_edit+0x165>
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <escape_dq@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10d0 <strcat@plt>
mov    %rbp,%rdi
call   1080 <commit_kit@plt>
add    $0x4118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.cmd_edit.mes = [128 x i8] c"[kit]edit plan to \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"n\00"
@optind = global i32 0
define void @cmd_edit(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [128 x [128 x i8]]
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = bitcast [128 x [128 x i8]]* %5 to i8*
%13 = bitcast [128 x i8]* %6 to i8*
store i32 0, i32* %11
%14 = load i32, i32* %3
%15 = load i8**, i8*** %4
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %11
br label %19
19: ; preds = %18, %2
%20 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %5, i64 0, i64 0
%21 = bitcast [128 x i8]* %20 to i8**
%22 = call i32 @read_kit_file(i32 127, i8** %21)
store i32 %22, i32* %9
%23 = load i32, i32* @optind
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %43
26: ; preds = %19
%27 = load i8**, i8*** %4
%28 = load i32, i32* @optind
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i64 @is_num(i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %26
%35 = load i8**, i8*** %4
%36 = load i32, i32* @optind
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %10
%41 = load i32, i32* @optind
%42 = add nsw i32 %41, 1
store i32 %42, i32* @optind
br label %44
43: ; preds = %26, %19
store i32 0, i32* %10
br label %44
44: ; preds = %43, %34
%45 = load i32, i32* %3
%46 = load i8**, i8*** %4
%47 = load i32, i32* @optind
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%49 = call i32 @gen_arg_str(i32 %45, i8** %46, i32 %47, i8* %48)
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %5, i64 0, i64 %51
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %52, i64 0, i64 0
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%55 = call i32 @strcpy(i8* %53, i8* %54)
%56 = load i32, i32* %9
%57 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %5, i64 0, i64 0
%58 = bitcast [128 x i8]* %57 to i8**
%59 = call i32 @save_kit_file(i32 %56, i8** %58)
%60 = load i32, i32* %11
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %44
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%64 = call i32 @escape_dq(i8* %63)
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%67 = call i32 @strcat(i8* %65, i8* %66)
%68 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%69 = call i32 @commit_kit(i8* %68)
br label %70
70: ; preds = %62, %44
ret void
}

LLVM IR (-O2):
@__const.cmd_edit.mes = [128 x i8] c"[kit]edit plan to \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"n\00"
@optind = global i32 0
define void @cmd_edit(i32 %0, i8** %1) {
%3 = alloca [128 x [128 x i8]]
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %3, i64 0, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
%11 = bitcast [128 x [128 x i8]]* %3 to i8**
%12 = call i32 @read_kit_file(i32 127, i8** %11)
%13 = load i32, i32* @optind
%14 = icmp slt i32 %13, %0
br i1 %14, label %15, label %29
15: ; preds = %2
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @is_num(i8* %18)
%20 = icmp eq i64 %19, 0
%21 = load i32, i32* @optind
br i1 %20, label %22, label %29
22: ; preds = %15
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = add nsw i32 %21, 1
store i32 %27, i32* @optind
%28 = sext i32 %26 to i64
br label %29
29: ; preds = %15, %2, %22
%30 = phi i32 [ %27, %22 ], [ %13, %2 ], [ %21, %15 ]
%31 = phi i64 [ %28, %22 ], [ 0, %2 ], [ 0, %15 ]
%32 = call i32 @gen_arg_str(i32 %0, i8** %1, i32 %30, i8* %8)
%33 = getelementptr inbounds [128 x [128 x i8]], [128 x [128 x i8]]* %3, i64 0, i64 %31, i64 0
%34 = call i32 @strcpy(i8* %33, i8* %8)
%35 = call i32 @save_kit_file(i32 %12, i8** %11)
br i1 %10, label %36, label %40
36: ; preds = %29
%37 = call i32 @escape_dq(i8* %8)
%38 = call i32 @strcat(i8* %7, i8* %8)
%39 = call i32 @commit_kit(i8* %7)
br label %40
40: ; preds = %36, %29
ret void
}