// File: /workspace/github_c_makefile_star2_O0/arachsys[P]init/pivot.c
// Function: main
int main(int argc, char **argv) {
  int old, new;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s NEW-ROOT [PUT-OLD]\n", argv[0]);
    return 64;
  }

  if (argc > 2) {
    if (syscall(__NR_pivot_root, argv[1], argv[2]) < 0)
      err(EXIT_FAILURE, "cannot pivot to new root %s", argv[1]);
    return EXIT_SUCCESS;
  }

  if (old = open("/", O_DIRECTORY | O_RDONLY), old < 0)
    err(EXIT_FAILURE, "cannot open /");
  if (new = open(argv[1], O_DIRECTORY | O_RDONLY), new < 0)
    err(EXIT_FAILURE, "cannot open %s", argv[1]);
  if (fchdir(new) < 0 || syscall(__NR_pivot_root, ".", ".") < 0)
    err(EXIT_FAILURE, "cannot pivot to new root %s", argv[1]);

  if (fchdir(old) < 0)
    err(EXIT_FAILURE, "cannot re-enter old root");
  if (mount("", ".", "", MS_SLAVE | MS_REC, NULL) < 0)
    err(EXIT_FAILURE, "cannot disable old root mount propagation");
  if (umount2(".", MNT_DETACH) < 0)
    err(EXIT_FAILURE, "cannot detach old root");

  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x11e7
movq 0x2e35(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xe30(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x1050
movl $0x40, -0x4(%rbp)
jmp 0x1369
cmpl $0x2, -0x8(%rbp)
jle 0x1236
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x9b, %edi
movb $0x0, %al
callq 0x1060
cmpq $0x0, %rax
jge 0x122a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %edi
leaq 0xdff(%rip), %rsi       # 0x2022
movb $0x0, %al
callq 0x1070
movl $0x0, -0x4(%rbp)
jmp 0x1369
leaq 0xe0d(%rip), %rdi       # 0x204a
movl $0x10000, %esi          # imm = 0x10000
movb $0x0, %al
callq 0x1090
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x1265
movl $0x1, %edi
leaq 0xde0(%rip), %rsi       # 0x203e
movb $0x0, %al
callq 0x1070
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
movb $0x0, %al
callq 0x1090
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x129d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %edi
leaq 0xdb6(%rip), %rsi       # 0x204c
movb $0x0, %al
callq 0x1070
movl -0x18(%rbp), %edi
callq 0x1080
cmpl $0x0, %eax
jl 0x12c6
movl $0x9b, %edi
leaq 0xda5(%rip), %rdx       # 0x205b
movq %rdx, %rsi
movb $0x0, %al
callq 0x1060
cmpq $0x0, %rax
jge 0x12e1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %edi
leaq 0xd48(%rip), %rsi       # 0x2022
movb $0x0, %al
callq 0x1070
movl -0x14(%rbp), %edi
callq 0x1080
cmpl $0x0, %eax
jge 0x1301
movl $0x1, %edi
leaq 0xd63(%rip), %rsi       # 0x205d
movb $0x0, %al
callq 0x1070
leaq 0xd19(%rip), %rdx       # 0x2021
leaq 0xd4c(%rip), %rsi       # 0x205b
movl $0x84000, %ecx          # imm = 0x84000
xorl %eax, %eax
movl %eax, %r8d
movq %rdx, %rdi
callq 0x1040
cmpl $0x0, %eax
jge 0x1339
movl $0x1, %edi
leaq 0xd44(%rip), %rsi       # 0x2076
movb $0x0, %al
callq 0x1070
leaq 0xd1b(%rip), %rdi       # 0x205b
movl $0x2, %esi
callq 0x1030
cmpl $0x0, %eax
jge 0x1362
movl $0x1, %edi
leaq 0xd45(%rip), %rsi       # 0x20a0
movb $0x0, %al
callq 0x1070
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq