// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq $0x0, -0x10(%rbp)
leaq 0x5125(%rip), %rdi      # 0x1060f
callq 0x6780
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb510
movq -0x8(%rbp), %rsi
movl $0x31, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
jmp 0xbc1e
movl $0x4, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb569
movq -0x8(%rbp), %rsi
movl $0x18, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
leaq 0x50d2(%rip), %rdi      # 0x1060f
callq 0x6780
cmpq $0x0, %rax
jne 0xb564
callq 0xae60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
leaq 0x50b0(%rip), %rdi      # 0x1060f
callq 0x7730
jmp 0xbc1c
movl $0x7, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb5fa
movq -0x8(%rbp), %rsi
movl $0x1b, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
leaq 0x4f6c(%rip), %rdi      # 0x10502
callq 0x7730
callq 0xae60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
leaq 0x505b(%rip), %rdi      # 0x1060d
callq 0x7730
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x8, %edi
callq 0x7060
cmpq $0x0, %rax
je 0xb5e9
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0xb5f5
movq -0x10(%rbp), %rax
movq $0x0, 0x48(%rax)
jmp 0xbc1a
movl $0x5, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb65d
movq -0x8(%rbp), %rsi
movl $0x19, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
leaq 0x4edb(%rip), %rdi      # 0x10502
callq 0x7730
callq 0xae60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
leaq 0x4fca(%rip), %rdi      # 0x1060d
callq 0x7730
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0xbc18
movl $0x6, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb6de
movq -0x8(%rbp), %rsi
movl $0x19, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x50(%rax)
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x5, %edi
callq 0xbc40
leaq 0x4e56(%rip), %rdi      # 0x10502
callq 0x7730
callq 0xae60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
leaq 0x4f45(%rip), %rdi      # 0x1060d
callq 0x7730
leaq 0x4f3b(%rip), %rdi      # 0x1060f
callq 0x7730
jmp 0xbc16
movl $0x9, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb818
movq -0x8(%rbp), %rsi
movl $0x1c, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
callq 0xb1d0
movq %rax, -0x18(%rbp)
leaq 0x4dea(%rip), %rdi      # 0x10502
callq 0x7730
leaq 0x4eeb(%rip), %rdi      # 0x1060f
callq 0x6780
cmpq $0x0, %rax
je 0xb73d
movq -0x10(%rbp), %rax
movq $0x0, 0x58(%rax)
jmp 0xb782
leaq 0x9e8c(%rip), %rax      # 0x155d0
movq (%rax), %rdi
callq 0x6fc0
testb $0x1, %al
jne 0xb752
jmp 0xb764
callq 0xbc90
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
jmp 0xb780
callq 0xc0b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
leaq 0x4e94(%rip), %rdi      # 0x1060f
callq 0x7730
jmp 0xb782
leaq 0x4e86(%rip), %rdi      # 0x1060f
callq 0x6780
cmpq $0x0, %rax
je 0xb7a2
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0xb7be
callq 0xae60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
leaq 0x4e56(%rip), %rdi      # 0x1060f
callq 0x7730
leaq 0x4e48(%rip), %rdi      # 0x1060d
callq 0x6780
cmpq $0x0, %rax
je 0xb7de
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0xb7fa
callq 0xc0b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
leaq 0x4e18(%rip), %rdi      # 0x1060d
callq 0x7730
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rdi
callq 0xb3f0
jmp 0xbc14
leaq 0x4a71(%rip), %rdi      # 0x10290
callq 0x6780
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb8d4
movq -0x8(%rbp), %rsi
movl $0x1a, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
callq 0xb1d0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0xc8, %edx
callq 0x20c0
leaq -0xf0(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq 0x4a26(%rip), %rdi      # 0x102a2
callq 0x6780
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb890
jmp 0xb8b7
callq 0xb4d0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0xf8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xf8(%rbp)
jmp 0xb875
movq -0xc0(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rdi
callq 0xb3f0
jmp 0xbc12
movl $0x18, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb90b
leaq 0x4d20(%rip), %rdi      # 0x1060f
callq 0x7730
movq -0x8(%rbp), %rsi
movl $0x2a, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
jmp 0xbc10
movl $0x19, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb942
leaq 0x4ce9(%rip), %rdi      # 0x1060f
callq 0x7730
movq -0x8(%rbp), %rsi
movl $0x2b, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
jmp 0xbc0e
movl $0x1a, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xb997
callq 0x79d0
movq %rax, -0x100(%rbp)
leaq 0x4ca6(%rip), %rdi      # 0x1060f
callq 0x7730
movq -0x8(%rbp), %rsi
movl $0x2c, %edi
callq 0x6980
movq %rax, -0x10(%rbp)
movq -0x100(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa0(%rax)
jmp 0xbc0c
movl $0x1b, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xba24
leaq 0x4b50(%rip), %rdi      # 0x10502
callq 0x7730
callq 0xae60
movq %rax, -0x108(%rbp)
leaq 0x4c43(%rip), %rdi      # 0x1060d
callq 0x7730
movq -0x108(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl $0x2e, %edi
callq 0x8a80
movq %rax, -0x10(%rbp)
movq 0x9bb9(%rip), %rax      # 0x155a8
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rax
movq %rax, 0x9ba7(%rip)      # 0x155a8
callq 0xb4d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x110(%rbp), %rax
movq %rax, 0x9b89(%rip)      # 0x155a8
jmp 0xbc0a
movl $0x1c, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xbada
cmpq $0x0, 0x9b64(%rip)      # 0x155a8
jne 0xba5c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x50aa(%rip), %rsi      # 0x10aff
movb $0x0, %al
callq 0x65d0
callq 0x7a50
movl %eax, -0x114(%rbp)
leaq 0x3a2b(%rip), %rdi      # 0xf499
callq 0x7730
callq 0xb4d0
movq %rax, %rsi
movq -0x8(%rbp), %rdx
movl $0x2f, %edi
callq 0x8a80
movq %rax, -0x10(%rbp)
movslq -0x114(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xb0(%rax)
movq 0x9af7(%rip), %rax      # 0x155a8
movq 0xc0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xc0(%rax)
movq -0x10(%rbp), %rcx
movq 0x9ada(%rip), %rax      # 0x155a8
movq %rcx, 0xc0(%rax)
jmp 0xbc08
movl $0x1d, %edi
callq 0x7060
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0xbb56
cmpq $0x0, 0x9ab2(%rip)      # 0x155a8
jne 0xbb0e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x4ff8(%rip), %rsi      # 0x10aff
movb $0x0, %al
callq 0x65d0
leaq 0x3984(%rip), %rdi      # 0xf499
callq 0x7730
callq 0xb4d0
movq %rax, %rsi
movq -0x8(%rbp), %rdx
movl $0x2f, %edi
callq 0x8a80
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0xb0(%rax)
movq -0x10(%rbp), %rcx
movq 0x9a5e(%rip), %rax      # 0x155a8
movq %rcx, 0xb8(%rax)
jmp 0xbc06
leaq 0x9a73(%rip), %rax      # 0x155d0
movq (%rax), %rax
movq %rax, -0x120(%rbp)
callq 0x7630
movq %rax, -0x128(%rbp)
leaq 0x391f(%rip), %rdi      # 0xf499
callq 0x6780
cmpq $0x0, %rax
je 0xbbcc
callq 0xb4d0
movq %rax, %rsi
movq -0x128(%rbp), %rdx
movl $0x2d, %edi
callq 0x8a80
movq %rax, -0x10(%rbp)
movq -0x128(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x128(%rbp), %rax
movl 0x20(%rax), %esi
callq 0x6690
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa0(%rax)
jmp 0xbc04
movq -0x120(%rbp), %rcx
leaq 0x99f6(%rip), %rax      # 0x155d0
movq %rcx, (%rax)
callq 0xbc90
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xbc02
callq 0xc0b0
movq %rax, -0x10(%rbp)
leaq 0x4a12(%rip), %rdi      # 0x1060f
callq 0x7730
jmp 0xbc04
jmp 0xbc06
jmp 0xbc08
jmp 0xbc0a
jmp 0xbc0c
jmp 0xbc0e
jmp 0xbc10
jmp 0xbc12
jmp 0xbc14
jmp 0xbc16
jmp 0xbc18
jmp 0xbc1a
jmp 0xbc1c
jmp 0xbc1e
movq -0x10(%rbp), %rdi
callq 0xdb80
movq -0x10(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)