// File: /workspace/github_c_makefile_star2_O3/pocari[P]compilerbook-9cc/parser.c
// Function: stmt
static Node *stmt() {
  Token *tk;
  Node *node = NULL;

  if (tk = consume(";")) {
    node = new_node(ND_NULL, tk);
  } else if (tk = consume_kind(TK_RETURN)) {
    node = new_node(ND_RETURN, tk);
    if (!consume(";")) {
      node->lhs = expr();
      expect(";");
    }
  } else if (tk = consume_kind(TK_IF)) {
    node = new_node(ND_IF, tk);

    expect("(");
    node->cond = expr();
    expect(")");
    node->then = stmt();

    // elseがあればパース
    if (consume_kind(TK_ELSE)) {
      node->els = stmt();
    } else {
      node->els = NULL;
    }
  } else if (tk = consume_kind(TK_WHILE)) {
    node = new_node(ND_WHILE, tk);

    expect("(");
    node->cond = expr();
    expect(")");
    node->body = stmt();
  } else if (tk = consume_kind(TK_DO)) {
    node = new_node(ND_WHILE, tk);
    node->is_do_while = true;
    node->body = stmt();
    expect_kind(TK_WHILE);
    expect("(");
    node->cond = expr();
    expect(")");
    expect(";");
  } else if (tk = consume_kind(TK_FOR)) {
    node = new_node(ND_FOR, tk);
    Scope *sc = enter_scope();
    expect("(");
    if (consume(";")) {
      //次が";"なら初期化式なしなのでNULL入れる
      node->init = NULL;
    } else {
      // ";"でないなら初期化式かまたは辺宣言あるのでパース
      if (is_type(token)) {
        node->init = var_decl();
      } else {
        node->init = read_expr_stmt();
        expect(";");
      }
    }
    if (consume(";")) {
      //次が";"なら条件式なしなのでNULL入れる
      node->cond = NULL;
    } else {
      // ";"でないなら条件式があるのでパース
      node->cond = expr();
      expect(";");
    }
    if (consume(")")) {
      //次が")"なら継続式なしなのでNULL入れる
      node->inc = NULL;
    } else {
      // ")"でないなら継続式があるのでパース
      node->inc = read_expr_stmt();
      expect(")");
    }
    node->body = stmt();
    leave_scope(sc);
  } else if (tk = consume("{")) {
    node = new_node(ND_BLOCK, tk);
    Scope *sc = enter_scope();
    int i = 0;
    Node head = {};
    Node *cur = &head;
    while (!consume("}")) {
      cur->next = stmt();
      cur = cur->next;
    }
    node->body = head.next;
    leave_scope(sc);
  } else if (tk = consume_kind(TK_BREAK)) {
    expect(";");
    node = new_node(ND_BREAK, tk);
  } else if (tk = consume_kind(TK_CONTINUE)) {
    expect(";");
    node = new_node(ND_CONTINUE, tk);
  } else if (tk = consume_kind(TK_GOTO)) {
    char *ident = expect_ident();
    expect(";");
    node = new_node(ND_GOTO, tk);
    node->label_name = ident;
  } else if (tk = consume_kind(TK_SWITCH)) {
    expect("(");
    Node *switch_condition = expr();
    expect(")");
    node = new_unary_node(ND_SWITCH, switch_condition, tk);

    // 今のswitchを保存して現在のswitchに切り替える
    Node *tmp = current_switch;
    current_switch = node;
    node->body = stmt();
    // もとのswitchに戻す
    current_switch = tmp;
  } else if (tk = consume_kind(TK_CASE)) {
    if (!current_switch) {
      error(tk->str, "対応するswitchがありません");
    }
    int case_cond_val = const_expr();
    expect(":");
    node = new_unary_node(ND_CASE, stmt(), tk);
    node->case_cond_val = case_cond_val;
    node->is_default_case = false;
    node->case_next = current_switch->case_next;
    current_switch->case_next = node;
  } else if (tk = consume_kind(TK_DEFAULT)) {
    if (!current_switch) {
      error(tk->str, "対応するswitchがありません");
    }
    expect(":");
    node = new_unary_node(ND_CASE, stmt(), tk);
    node->is_default_case = true;
    current_switch->default_case = node;
  } else {
    Token *tmp = token;
    Token *tk = consume_ident();
    if (consume(":")) {
      // identの次に":" が来てたらラベル
      node = new_unary_node(ND_LABEL, stmt(), tk);
      node->label_name = my_strndup(tk->str, tk->len);
    } else {
      // ラベルじゃなかったので、もとに戻す
      token = tmp;
      // キーワードじゃなかったら 変数宣言かどうかチェック
      node = var_decl();
      if (!node) {
        // 変数宣言でなかったら式文
        node = read_expr_stmt();
        expect(";");
      }
    }
  }

  add_type(node);
  return node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq 0x4027(%rip), %rdi      # 0xc6ba
callq 0x51eb
leaq 0x7de1(%rip), %rbp      # 0x10480
movq (%rbp), %r12
testb %al, %al
je 0x86e9
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x31, (%rax)
movq %r12, 0x8(%rax)
movq %rbx, %rdi
callq 0x9eef
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r12), %ebx
leal -0x4(%rbx), %eax
cmpl $0x5, %eax
ja 0x8748
leaq 0x3f58(%rip), %rcx      # 0xc654
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r12), %r14
movq %r14, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x18, (%rax)
movq %r12, 0x8(%rax)
leaq 0x3f89(%rip), %rdi      # 0xc6ba
callq 0x51eb
testb %al, %al
je 0x89ae
movq 0x8(%r14), %rax
movq %rax, (%rbp)
jmp 0x86cc
leaq 0x3bc7(%rip), %rdi      # 0xc316
callq 0x51eb
testb %al, %al
je 0x8960
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1a, (%rax)
movq %r12, 0x8(%rax)
callq 0x864e
movq %rax, %r14
movq %rsp, %r15
movl $0xc8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
leaq 0x3f0b(%rip), %rdi      # 0xc6ad
callq 0x51eb
testb %al, %al
jne 0x87cd
leaq 0x3efb(%rip), %r12      # 0xc6ad
callq 0x867b
movq %rax, %r13
movq %rax, 0x30(%r15)
movq %r12, %rdi
callq 0x51eb
movq %r13, %r15
testb %al, %al
je 0x87b2
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movq 0x30(%rsp), %rax
jmp 0x8a5d
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x19, (%rax)
movq %r12, 0x8(%rax)
movb $0x1, 0x50(%rax)
callq 0x867b
movq %rax, 0x28(%rbx)
callq 0x8d5e
leaq 0x3d55(%rip), %rdi      # 0xc576
callq 0x5b5c
callq 0x859b
movq %rax, 0x38(%rbx)
leaq 0x3d53(%rip), %rdi      # 0xc589
callq 0x5b5c
jmp 0x89b7
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x19, (%rax)
movq %r12, 0x8(%rax)
leaq 0x3d0a(%rip), %rdi      # 0xc576
callq 0x5b5c
callq 0x859b
movq %rax, 0x38(%rbx)
leaq 0x3d08(%rip), %rdi      # 0xc589
callq 0x5b5c
callq 0x867b
movq %rax, 0x28(%rbx)
jmp 0x86cc
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1b, (%rax)
movq %r12, 0x8(%rax)
leaq 0x3cb6(%rip), %rdi      # 0xc576
callq 0x5b5c
callq 0x859b
movq %rax, 0x38(%rbx)
leaq 0x3cb4(%rip), %rdi      # 0xc589
callq 0x5b5c
callq 0x867b
movq %rax, 0x40(%rbx)
movq (%rbp), %rax
cmpl $0x8, (%rax)
jne 0x86cc
movq 0x8(%rax), %rax
movq %rax, (%rbp)
callq 0x867b
movq %rax, 0x48(%rbx)
jmp 0x86cc
movq 0x8(%r12), %rax
movq %rax, (%rbp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1c, (%rax)
movq %r12, 0x8(%rax)
callq 0x864e
movq %rax, %r14
leaq 0x3c3c(%rip), %rdi      # 0xc576
callq 0x5b5c
leaq 0x3d74(%rip), %rdi      # 0xc6ba
callq 0x51eb
movq (%rbp), %rdi
testb %al, %al
je 0x89c8
movq 0x8(%rdi), %rax
movq %rax, (%rbp)
jmp 0x89f2
leal -0x18(%rbx), %eax
cmpl $0x5, %eax
ja 0x8a81
leaq 0x3cf9(%rip), %rcx      # 0xc66c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r12), %rax
movq %rax, (%rbp)
leaq 0x3d2e(%rip), %rdi      # 0xc6ba
callq 0x5b5c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2a, (%rax)
jmp 0x86c8
callq 0x859b
movq %rax, 0x18(%rbx)
leaq 0x3cfc(%rip), %rdi      # 0xc6ba
callq 0x5b5c
jmp 0x86cc
movl (%rdi), %eax
leal -0xa(%rax), %ecx
cmpl $0x6, %ecx
jb 0x89e9
cmpl $0x17, %eax
ja 0x8d0f
movl $0xe30000, %ecx         # imm = 0xE30000
btl %eax, %ecx
jae 0x8d0f
callq 0x8d98
movq %rax, 0x58(%rbx)
leaq 0x3cc1(%rip), %rdi      # 0xc6ba
callq 0x51eb
testb %al, %al
je 0x8a10
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
jmp 0x8a25
callq 0x859b
movq %rax, 0x38(%rbx)
leaq 0x3c9a(%rip), %rdi      # 0xc6ba
callq 0x5b5c
leaq 0x3b5d(%rip), %rdi      # 0xc589
callq 0x51eb
testb %al, %al
je 0x8a43
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
jmp 0x8a58
callq 0x92c6
movq %rax, 0x60(%rbx)
leaq 0x3b36(%rip), %rdi      # 0xc589
callq 0x5b5c
callq 0x867b
movq %rax, 0x28(%rbx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rax, 0x79d1(%rip)      # 0x10440
movq %rcx, 0x79c2(%rip)      # 0x10438
decl 0x79b4(%rip)            # 0x10430
jmp 0x86cc
cmpl $0x2, %ebx
jne 0x8b6f
movq 0x8(%r12), %rbx
movq %rbx, (%rbp)
movq %r12, %r15
jmp 0x8b75
movq 0x8(%r12), %rax
movq %rax, (%rbp)
cmpq $0x0, 0x79ac(%rip)      # 0x10458
je 0x8d4b
callq 0x5fef
movq %rax, %rdi
xorl %esi, %esi
callq 0x5c54
movq %rax, %r14
leaq 0x2a56(%rip), %rdi      # 0xb521
callq 0x5b5c
callq 0x867b
movq %rax, %r15
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2f, (%rax)
movq %r12, 0x8(%rax)
movq %r15, 0x18(%rax)
movslq %r14d, %rax
movq %rax, 0xa8(%rbx)
movb $0x0, 0xb0(%rbx)
movq 0x7948(%rip), %rax      # 0x10458
movq 0xc0(%rax), %rcx
movq %rcx, 0xc0(%rbx)
movq %rbx, 0xc0(%rax)
jmp 0x86cc
movq 0x8(%r12), %rax
movq %rax, (%rbp)
callq 0x5bde
movq %rax, %r14
leaq 0x3b78(%rip), %rdi      # 0xc6ba
callq 0x5b5c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2c, (%rax)
movq %r12, 0x8(%rax)
movq %r14, 0xa0(%rax)
jmp 0x86cc
xorl %r15d, %r15d
movq %r12, %rbx
leaq 0x29a5(%rip), %rdi      # 0xb521
callq 0x51eb
testb %al, %al
je 0x8bea
movq 0x8(%rbx), %rax
movq %rax, (%rbp)
callq 0x867b
movq %rax, %r14
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2d, (%rax)
movq %r15, 0x8(%rax)
movq %r14, 0x18(%rax)
movq 0x18(%r15), %r12
movslq 0x20(%r15), %r14
leaq 0x1(%r14), %rdi
movl $0x1, %esi
callq 0x2100
movq %rax, %r15
testq %r14, %r14
jle 0x8d37
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2150
jmp 0x8d3a
movq %r12, (%rbp)
callq 0x8d98
movq %rax, %rbx
testq %rax, %rax
jne 0x86cc
callq 0x92c6
movq %rax, %rbx
jmp 0x89b7
movq 0x8(%r12), %rax
movq %rax, (%rbp)
leaq 0x395a(%rip), %rdi      # 0xc576
callq 0x5b5c
callq 0x859b
movq %rax, %r14
leaq 0x3959(%rip), %rdi      # 0xc589
callq 0x5b5c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2e, (%rax)
movq %r12, 0x8(%rax)
movq %r14, 0x18(%rax)
movq 0x77fc(%rip), %r14      # 0x10458
movq %rax, 0x77f5(%rip)      # 0x10458
callq 0x867b
movq %rax, 0x28(%rbx)
movq %r14, 0x77e5(%rip)      # 0x10458
jmp 0x86cc
movq 0x8(%r12), %rax
movq %rax, (%rbp)
leaq 0x3a32(%rip), %rdi      # 0xc6ba
callq 0x5b5c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2b, (%rax)
jmp 0x86c8
movq 0x8(%r12), %rax
movq %rax, (%rbp)
cmpq $0x0, 0x779d(%rip)      # 0x10458
je 0x8d4b
leaq 0x2859(%rip), %rdi      # 0xb521
callq 0x5b5c
callq 0x867b
movq %rax, %r14
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2f, (%rax)
movq %r12, 0x8(%rax)
movq %r14, 0x18(%rax)
movb $0x1, 0xb0(%rax)
movq 0x7755(%rip), %rax      # 0x10458
movq %rbx, 0xb8(%rax)
jmp 0x86cc
callq 0x59dc
testq %rax, %rax
jne 0x89e9
callq 0x92c6
movq %rax, 0x58(%rbx)
leaq 0x398d(%rip), %rdi      # 0xc6ba
callq 0x5b5c
jmp 0x89f2
xorl %r14d, %r14d
movb $0x0, (%r15,%r14)
movq %r15, 0xa0(%rbx)
jmp 0x86cc
movq 0x18(%r12), %rdi
leaq 0x3e31(%rip), %rsi      # 0xcb88
xorl %eax, %eax
callq 0x4a3b