// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd0, %rsp
leaq 0x3d10(%rip), %rdi      # 0xc672
callq 0x5244
testb %al, %al
je 0x897e
leaq 0x7b0e(%rip), %rax      # 0x10480
movq (%rax), %r14
movq 0x8(%r14), %rcx
movq %rcx, (%rax)
jmp 0x8981
xorl %r14d, %r14d
testq %r14, %r14
je 0x89a7
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x31, (%rax)
movq %r14, 0x8(%rax)
jmp 0x8b0f
leaq 0x7ad2(%rip), %r13      # 0x10480
movq (%r13), %r14
cmpl $0x4, (%r14)
jne 0x89c2
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x89c5
xorl %r14d, %r14d
testq %r14, %r14
je 0x8a25
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x18, (%rax)
movq %r14, 0x8(%rax)
leaq 0x3c85(%rip), %rdi      # 0xc672
callq 0x5244
testb %al, %al
je 0x8a0b
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
jne 0x8b0f
callq 0x8870
movq %rax, 0x18(%rbx)
leaq 0x3c57(%rip), %rdi      # 0xc672
callq 0x5c3c
jmp 0x8b0f
movq (%r13), %r14
cmpl $0x7, (%r14)
jne 0x8a39
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8a3c
xorl %r14d, %r14d
testq %r14, %r14
je 0x8aa3
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1b, (%rax)
movq %r14, 0x8(%rax)
leaq 0x3b12(%rip), %rdi      # 0xc576
callq 0x5c3c
callq 0x8870
movq %rax, 0x38(%rbx)
leaq 0x3b10(%rip), %rdi      # 0xc589
callq 0x5c3c
callq 0x894b
movq %rax, 0x40(%rbx)
movq (%r13), %rax
cmpl $0x8, (%rax)
jne 0x8ab7
movq 0x8(%rax), %rax
movq %rax, (%r13)
callq 0x894b
movq %rax, 0x48(%rbx)
jmp 0x8b0f
movq (%r13), %r14
cmpl $0x5, (%r14)
jne 0x8ac1
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8ac4
movq $0x0, 0x48(%rbx)
jmp 0x8b0f
xorl %r14d, %r14d
testq %r14, %r14
je 0x8b2b
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x19, (%rax)
movq %r14, 0x8(%rax)
leaq 0x3a8a(%rip), %rdi      # 0xc576
callq 0x5c3c
callq 0x8870
movq %rax, 0x38(%rbx)
leaq 0x3a88(%rip), %rdi      # 0xc589
callq 0x5c3c
callq 0x894b
movq %rax, 0x28(%rbx)
movq %rbx, %rdi
callq 0xa308
movq %rbx, %rax
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq (%r13), %r14
cmpl $0x6, (%r14)
jne 0x8b3f
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8b42
xorl %r14d, %r14d
testq %r14, %r14
je 0x8b9b
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x19, (%rax)
movq %r14, 0x8(%rax)
movb $0x1, 0x50(%rax)
callq 0x894b
movq %rax, 0x28(%rbx)
callq 0x9113
leaq 0x39fa(%rip), %rdi      # 0xc576
callq 0x5c3c
callq 0x8870
movq %rax, 0x38(%rbx)
leaq 0x39f8(%rip), %rdi      # 0xc589
callq 0x5c3c
jmp 0x8a14
movq (%r13), %r14
cmpl $0x9, (%r14)
jne 0x8baf
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8bb2
xorl %r14d, %r14d
testq %r14, %r14
je 0x8cce
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1c, (%rax)
movq %r14, 0x8(%rax)
callq 0x891e
movq %rax, %r14
leaq 0x3990(%rip), %rdi      # 0xc576
callq 0x5c3c
leaq 0x3a80(%rip), %rdi      # 0xc672
callq 0x5244
testb %al, %al
je 0x8c16
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
je 0x8c16
movq $0x0, 0x58(%rbx)
jmp 0x8c44
movq (%r13), %rdi
movl (%rdi), %eax
leal -0xa(%rax), %ecx
cmpl $0x6, %ecx
jb 0x8c3b
cmpl $0x17, %eax
ja 0x8de4
movl $0xe30000, %ecx         # imm = 0xE30000
btl %eax, %ecx
jae 0x8de4
callq 0x9150
movq %rax, 0x58(%rbx)
leaq 0x3a27(%rip), %rdi      # 0xc672
callq 0x5244
testb %al, %al
je 0x8c6f
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
je 0x8c6f
movq $0x0, 0x38(%rbx)
jmp 0x8c84
callq 0x8870
movq %rax, 0x38(%rbx)
leaq 0x39f3(%rip), %rdi      # 0xc672
callq 0x5c3c
leaq 0x38fe(%rip), %rdi      # 0xc589
callq 0x5244
testb %al, %al
je 0x8caf
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
je 0x8caf
movq $0x0, 0x60(%rbx)
jmp 0x8cc4
callq 0x96a8
movq %rax, 0x60(%rbx)
leaq 0x38ca(%rip), %rdi      # 0xc589
callq 0x5c3c
callq 0x894b
jmp 0x8d67
leaq 0x3641(%rip), %rdi      # 0xc316
callq 0x5244
testb %al, %al
je 0x8cec
movq (%r13), %r14
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8cef
xorl %r14d, %r14d
testq %r14, %r14
je 0x8d8b
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x1a, (%rax)
movq %r14, 0x8(%rax)
callq 0x891e
movq %rax, %r14
leaq 0x8(%rsp), %r15
movl $0xc8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
leaq 0x392e(%rip), %r12      # 0xc665
movq %r12, %rdi
callq 0x5244
testb %al, %al
je 0x8d54
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
jne 0x8d62
callq 0x894b
movq %rax, 0x30(%r15)
movq %rax, %r15
jmp 0x8d37
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rbx)
movq (%r14), %rax
movq %rax, 0x76cb(%rip)      # 0x10440
movq 0x8(%r14), %rax
movq %rax, 0x76b8(%rip)      # 0x10438
decl 0x76aa(%rip)            # 0x10430
jmp 0x8b0f
movq (%r13), %r14
cmpl $0x18, (%r14)
jne 0x8d9f
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8da2
xorl %r14d, %r14d
testq %r14, %r14
je 0x8dd0
leaq 0x38c4(%rip), %rdi      # 0xc672
callq 0x5c3c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2a, (%rax)
jmp 0x899e
movq (%r13), %r14
cmpl $0x19, (%r14)
jne 0x8e0c
movq 0x8(%r14), %rax
movq %rax, (%r13)
jmp 0x8e0f
callq 0x5ac1
testq %rax, %rax
jne 0x8c3b
callq 0x96a8
movq %rax, 0x58(%rbx)
leaq 0x3870(%rip), %rdi      # 0xc672
callq 0x5c3c
jmp 0x8c44
xorl %r14d, %r14d
testq %r14, %r14
je 0x8e3d
leaq 0x3857(%rip), %rdi      # 0xc672
callq 0x5c3c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2b, (%rax)
jmp 0x899e
movq (%r13), %r15
cmpl $0x1a, (%r15)
jne 0x8e51
movq 0x8(%r15), %rax
movq %rax, (%r13)
jmp 0x8e54
xorl %r15d, %r15d
testq %r15, %r15
je 0x8e95
callq 0x5cc0
movq %rax, %r14
leaq 0x380a(%rip), %rdi      # 0xc672
callq 0x5c3c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2c, (%rax)
movq %r15, 0x8(%rax)
movq %r14, 0xa0(%rax)
jmp 0x8b0f
movq (%r13), %r15
cmpl $0x1b, (%r15)
jne 0x8ea9
movq 0x8(%r15), %rax
movq %rax, (%r13)
jmp 0x8eac
xorl %r15d, %r15d
testq %r15, %r15
je 0x8f14
leaq 0x36be(%rip), %rdi      # 0xc576
callq 0x5c3c
callq 0x8870
movq %rax, %r14
leaq 0x36bd(%rip), %rdi      # 0xc589
callq 0x5c3c
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2e, (%rax)
movq %r15, 0x8(%rax)
movq %r14, 0x18(%rax)
movq 0x7560(%rip), %r14      # 0x10458
movq %rax, 0x7559(%rip)      # 0x10458
callq 0x894b
movq %rax, 0x28(%rbx)
movq %r14, 0x7549(%rip)      # 0x10458
jmp 0x8b0f
movq (%r13), %r12
cmpl $0x1c, (%r12)
jne 0x8f2a
movq 0x8(%r12), %rax
movq %rax, (%r13)
jmp 0x8f2d
xorl %r12d, %r12d
testq %r12, %r12
je 0x8fbc
cmpq $0x0, 0x751a(%rip)      # 0x10458
je 0x90fa
callq 0x60d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x5d39
movq %rax, %r14
leaq 0x25c4(%rip), %rdi      # 0xb521
callq 0x5c3c
callq 0x894b
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 0x74b6(%rip), %rax      # 0x10458
movq 0xc0(%rax), %rcx
movq %rcx, 0xc0(%rbx)
movq %rbx, 0xc0(%rax)
jmp 0x8b0f
movq (%r13), %r15
cmpl $0x1d, (%r15)
jne 0x8fd0
movq 0x8(%r15), %rax
movq %rax, (%r13)
jmp 0x8fd3
xorl %r15d, %r15d
testq %r15, %r15
je 0x9034
cmpq $0x0, 0x7478(%rip)      # 0x10458
je 0x9101
leaq 0x2534(%rip), %rdi      # 0xb521
callq 0x5c3c
callq 0x894b
movq %rax, %r14
movl $0x1, %edi
movl $0xc8, %esi
callq 0x2100
movq %rax, %rbx
movl $0x2f, (%rax)
movq %r15, 0x8(%rax)
movq %r14, 0x18(%rax)
movb $0x1, 0xb0(%rax)
movq 0x7430(%rip), %rax      # 0x10458
movq %rbx, 0xb8(%rax)
jmp 0x8b0f
movq (%r13), %rbx
cmpl $0x2, (%rbx)
jne 0x904a
movq 0x8(%rbx), %rax
movq %rax, (%r13)
movq %rbx, %r15
jmp 0x904d
xorl %r15d, %r15d
leaq 0x24cd(%rip), %rdi      # 0xb521
callq 0x5244
testb %al, %al
je 0x90c4
movq (%r13), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%r13)
testq %rax, %rax
je 0x90c4
callq 0x894b
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 0x90e6
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2150
jmp 0x90e9
movq %rbx, (%r13)
callq 0x9150
movq %rax, %rbx
testq %rax, %rax
jne 0x8b0f
callq 0x96a8
movq %rax, %rbx
jmp 0x8a14
xorl %r14d, %r14d
movb $0x0, (%r15,%r14)
movq %r15, 0xa0(%rbx)
jmp 0x8b0f
movq 0x18(%r12), %rdi
jmp 0x9105
movq 0x18(%r15), %rdi
leaq 0x3a34(%rip), %rsi      # 0xcb40
xorl %eax, %eax
callq 0x4a3b