#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*/ printf(char *, unsigned int);
char *strchr(char *, char);
int strlen(char *);
char *strtok(char *, char *);
scalar_t__ strtoul(char *, int /*<<< orphan*/ *, int);
int parse_line2cmd(char *line, unsigned int *cmd_buf, int *ins_num) {
  char *p, *digit, *rec;
  static int new_cmd = 0;
  unsigned int idx = 0;
  if (!line || !cmd_buf)
    return -1;
  if (((p = strchr(line, '{')) != NULL)) {
    if (strlen(line) > 3)
      p = p + 1;
    new_cmd = 1;
  } else {
    if (strlen(line) < 3)
      return -2;
    p = line;
  }
  if (!new_cmd)
    return -3;
  cmd_buf[idx] = (unsigned int)strtoul(p, NULL, 16);
  if (cmd_buf[idx] == 0)
    return -2;
  printf("====>the instruction is :0x%8x\n", cmd_buf[idx]);
  idx++;
  *ins_num = idx;
  rec = p;
  digit = strtok(p, ",");
  do {
    digit = strtok(NULL, ",");
    if (digit) {
      cmd_buf[idx] = (unsigned int)strtoul(digit, NULL, 16);
      rec = digit;
      printf("====>the instruction is :0x%8x\n", cmd_buf[idx]);
      idx++;
    }
  } while (digit);
  *ins_num = idx;
  if (strchr(rec, '}')) {
    new_cmd = 0;
    return 0;
  }
  return idx;
}


x86 assembly (clang, -O0):
<parse_line2cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1181 <parse_line2cmd+0x31>
cmpq   $0x0,-0x18(%rbp)
jne    118d <parse_line2cmd+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <parse_line2cmd+0x1f5>
mov    -0x10(%rbp),%rdi
mov    $0x7b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d6 <parse_line2cmd+0x86>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jle    11c7 <parse_line2cmd+0x77>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,0x2e7b(%rip)
jmp    11fc <parse_line2cmd+0xac>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jge    11f4 <parse_line2cmd+0xa4>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1345 <parse_line2cmd+0x1f5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,0x2e49(%rip)
jne    1215 <parse_line2cmd+0xc5>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1345 <parse_line2cmd+0x1f5>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
cmpl   $0x0,(%rax,%rcx,4)
jne    1250 <parse_line2cmd+0x100>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1345 <parse_line2cmd+0x1f5>
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xd9f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd81(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12f8 <parse_line2cmd+0x1a8>
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xd16(%rip),%rdi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12fd <parse_line2cmd+0x1ad>
cmpq   $0x0,-0x30(%rbp)
jne    1294 <parse_line2cmd+0x144>
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     133f <parse_line2cmd+0x1ef>
movl   $0x0,0x2d19(%rip)
movl   $0x0,-0x4(%rbp)
jmp    1345 <parse_line2cmd+0x1f5>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line2cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1297 <parse_line2cmd+0x147>
mov    %rsi,%r15
test   %rsi,%rsi
je     1297 <parse_line2cmd+0x147>
mov    %rdx,%r14
mov    %rdi,%rbx
mov    $0x7b,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rbp,%rbp
je     1274 <parse_line2cmd+0x124>
xor    %ecx,%ecx
cmp    $0x4,%eax
setge  %cl
add    %rcx,%rbp
movb   $0x1,0x2ea1(%rip)
mov    %rbp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %eax,(%r15)
test   %eax,%eax
je     1292 <parse_line2cmd+0x142>
lea    0xe31(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
movl   $0x1,(%r14)
lea    0xe3c(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1254 <parse_line2cmd+0x104>
lea    0xdf6(%rip),%r12
lea    0xe0f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %ebp,%ecx
mov    %eax,(%r15,%rcx,4)
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
add    $0x1,%ebp
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1220 <parse_line2cmd+0xd0>
mov    %ebp,(%r14)
mov    %rbx,%rdi
mov    $0x7d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1297 <parse_line2cmd+0x147>
movb   $0x0,0x2ddc(%rip)
xor    %ebp,%ebp
jmp    1297 <parse_line2cmd+0x147>
mov    $0xfffffffe,%ebp
cmp    $0x3,%eax
jl     1297 <parse_line2cmd+0x147>
mov    $0xfffffffd,%ebp
cmpb   $0x1,0x2dc2(%rip)
je     11ae <parse_line2cmd+0x5e>
jmp    1297 <parse_line2cmd+0x147>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@parse_line2cmd.new_cmd = internal global i32 0
@.str = [32 x i8] c"====>the instruction is :0x%8x\0A\00"
@.str.1 = [2 x i8] c",\00"
define i32 @parse_line2cmd(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 0, i32* %11
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14, %3
store i32 -1, i32* %4
br label %104
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 123)
store i8* %20, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = icmp sgt i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %8
br label %29
29: ; preds = %26, %22
store i32 1, i32* @parse_line2cmd.new_cmd
br label %37
30: ; preds = %18
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -2, i32* %4
br label %104
35: ; preds = %30
%36 = load i8*, i8** %5
store i8* %36, i8** %8
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* @parse_line2cmd.new_cmd
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %37
store i32 -3, i32* %4
br label %104
41: ; preds = %37
%42 = load i8*, i8** %8
%43 = call i64 @strtoul(i8* %42, i32* null, i32 16)
%44 = trunc i64 %43 to i32
%45 = load i32*, i32** %6
%46 = load i32, i32* %11
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
%49 = load i32*, i32** %6
%50 = load i32, i32* %11
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %41
store i32 -2, i32* %4
br label %104
56: ; preds = %41
%57 = load i32*, i32** %6
%58 = load i32, i32* %11
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %11
%64 = add i32 %63, 1
store i32 %64, i32* %11
%65 = load i32, i32* %11
%66 = load i32*, i32** %7
store i32 %65, i32* %66
%67 = load i8*, i8** %8
store i8* %67, i8** %10
%68 = load i8*, i8** %8
%69 = call i8* @strtok(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %69, i8** %9
br label %70
70: ; preds = %92, %56
%71 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %71, i8** %9
%72 = load i8*, i8** %9
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %91
74: ; preds = %70
%75 = load i8*, i8** %9
%76 = call i64 @strtoul(i8* %75, i32* null, i32 16)
%77 = trunc i64 %76 to i32
%78 = load i32*, i32** %6
%79 = load i32, i32* %11
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
store i32 %77, i32* %81
%82 = load i8*, i8** %9
store i8* %82, i8** %10
%83 = load i32*, i32** %6
%84 = load i32, i32* %11
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
%87 = load i32, i32* %86
%88 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %11
%90 = add i32 %89, 1
store i32 %90, i32* %11
br label %91
91: ; preds = %74, %70
br label %92
92: ; preds = %91
%93 = load i8*, i8** %9
%94 = icmp ne i8* %93, null
br i1 %94, label %70, label %95
95: ; preds = %92
%96 = load i32, i32* %11
%97 = load i32*, i32** %7
store i32 %96, i32* %97
%98 = load i8*, i8** %10
%99 = call i8* @strchr(i8* %98, i8 signext 125)
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %102
101: ; preds = %95
store i32 0, i32* @parse_line2cmd.new_cmd
store i32 0, i32* %4
br label %104
102: ; preds = %95
%103 = load i32, i32* %11
store i32 %103, i32* %4
br label %104
104: ; preds = %102, %101, %55, %40, %34, %17
%105 = load i32, i32* %4
ret i32 %105
}

LLVM IR (-O2):
@parse_line2cmd.new_cmd = internal unnamed_addr global i1 false
@.str = [32 x i8] c"====>the instruction is :0x%8x\0A\00"
@.str.1 = [2 x i8] c",\00"
define i32 @parse_line2cmd(i8* %0, i32* writeonly %1, i32* nocapture writeonly %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i32* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %46
7: ; preds = %3
%8 = tail call i8* @strchr(i8* %0, i8 signext 123)
%9 = icmp eq i8* %8, null
%10 = tail call i32 @strlen(i8* %0)
br i1 %9, label %15, label %11
11: ; preds = %7
%12 = icmp sgt i32 %10, 3
%13 = zext i1 %12 to i64
%14 = getelementptr i8, i8* %8, i64 %13
store i1 true, i1* @parse_line2cmd.new_cmd
br label %19
15: ; preds = %7
%16 = icmp slt i32 %10, 3
br i1 %16, label %46, label %17
17: ; preds = %15
%18 = load i1, i1* @parse_line2cmd.new_cmd
br i1 %18, label %19, label %46
19: ; preds = %11, %17
%20 = phi i8* [ %14, %11 ], [ %0, %17 ]
%21 = tail call i64 @strtoul(i8* nocapture %20, i32* null, i32 16)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %1
%23 = icmp eq i32 %22, 0
br i1 %23, label %46, label %24
24: ; preds = %19
%25 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 1, i32* %2
%26 = tail call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %40, label %29
29: ; preds = %24, %29
%30 = phi i8* [ %38, %29 ], [ %27, %24 ]
%31 = phi i32 [ %37, %29 ], [ 1, %24 ]
%32 = tail call i64 @strtoul(i8* nocapture %30, i32* null, i32 16)
%33 = trunc i64 %32 to i32
%34 = zext i32 %31 to i64
%35 = getelementptr inbounds i32, i32* %1, i64 %34
store i32 %33, i32* %35
%36 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %33)
%37 = add i32 %31, 1
%38 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %29
40: ; preds = %29, %24
%41 = phi i8* [ %20, %24 ], [ %30, %29 ]
%42 = phi i32 [ 1, %24 ], [ %37, %29 ]
store i32 %42, i32* %2
%43 = tail call i8* @strchr(i8* dereferenceable(1) %41, i8 signext 125)
%44 = icmp eq i8* %43, null
br i1 %44, label %46, label %45
45: ; preds = %40
store i1 false, i1* @parse_line2cmd.new_cmd
br label %46
46: ; preds = %40, %19, %17, %15, %3, %45
%47 = phi i32 [ 0, %45 ], [ -1, %3 ], [ -2, %15 ], [ -3, %17 ], [ -2, %19 ], [ %42, %40 ]
ret i32 %47
}