// File: /workspace/github_c_makefile_star2_O0/sos22[P]unexec/tests/signals.c
// Function: main
int main() {
    char template[] = "signalsXXXXXX";
    close(mkstemp(template));
    signal(SIGINT, siginthandler);
    int r = unexec(template, NULL);
    if (r < 0) err(1, "unexec %s", template);
    if (r == 1) {
        raise(SIGINT);
        assert(siginted);
        execl(template, template, NULL);
        err(1, "exec"); }
    if (unlink(template) < 0) err(1, "unlink %s", template);
    assert(!siginted);
    raise(SIGINT);
    assert(siginted);
    siginted = false;
    raise(SIGCHLD);
    assert(!siginted);
    stack_t ss = (stack_t){
        .ss_sp = malloc(16384),
        .ss_flags = 0,
        .ss_size = 16384,
    };
    printf("sigstack %p\n", ss.ss_sp);
    if (sigaltstack(&ss, NULL) < 0) err(1, "sigaltstack");
    printf("set sigaltstack\n");
    r = unexec(template, NULL);
    if (r < 0) err(1, "unexec2");
    if (r == 1) {
        execl(template, template, NULL);
        err(1, "exec2"); }
    assert(rsp < (unsigned long)ss.ss_sp ||
           rsp >= (unsigned long)ss.ss_sp + ss.ss_size);
    struct sigaction sa = {
        .sa_handler = siginthandler,
        .sa_flags = SA_ONSTACK, };
    if (sigaction(SIGINT, &sa, NULL) < 0) err(1, "sigaction");
    raise(SIGINT);
    printf("rsp %lx, wanted %p,%p\n",
           rsp, ss.ss_sp, ss.ss_sp + ss.ss_size);
    assert(rsp >= (unsigned long)ss.ss_sp);
    assert(rsp < (unsigned long)ss.ss_sp + ss.ss_size);
    if (unlink(template) < 0) err(1, "unlink2 %s", template);
    return 0; }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl $0x0, -0x4(%rbp)
movq 0xddb(%rip), %rax       # 0x2004
movq %rax, -0x12(%rbp)
movl 0xdd9(%rip), %eax       # 0x200c
movl %eax, -0xa(%rbp)
movw 0xdd3(%rip), %ax        # 0x2010
movw %ax, -0x6(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x10d0
movl %eax, %edi
callq 0x1080
movl $0x2, %edi
leaq 0x353(%rip), %rsi       # 0x15b0
callq 0x1090
leaq -0x12(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x128f
leaq -0x12(%rbp), %rdx
movl $0x1, %edi
leaq 0xd8a(%rip), %rsi       # 0x2012
movb $0x0, %al
callq 0x10b0
cmpl $0x1, -0x18(%rbp)
jne 0x12ef
movl $0x2, %edi
callq 0x1030
testb $0x1, 0x2dfa(%rip)      # 0x40a0
je 0x12aa
jmp 0x12c9
leaq 0xd96(%rip), %rdi       # 0x2047
leaq 0xd64(%rip), %rsi       # 0x201c
movl $0x1a, %edx
leaq 0xd68(%rip), %rcx       # 0x202c
callq 0x1070
leaq -0x12(%rbp), %rdi
leaq -0x12(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x1100
movl $0x1, %edi
leaq 0xd4f(%rip), %rsi       # 0x2037
movb $0x0, %al
callq 0x10b0
leaq -0x12(%rbp), %rdi
callq 0x1040
cmpl $0x0, %eax
jge 0x1314
leaq -0x12(%rbp), %rdx
movl $0x1, %edi
leaq 0xd2f(%rip), %rsi       # 0x203c
movb $0x0, %al
callq 0x10b0
testb $0x1, 0x2d85(%rip)      # 0x40a0
jne 0x131f
jmp 0x133e
leaq 0xd20(%rip), %rdi       # 0x2046
leaq 0xcef(%rip), %rsi       # 0x201c
movl $0x1e, %edx
leaq 0xcf3(%rip), %rcx       # 0x202c
callq 0x1070
movl $0x2, %edi
callq 0x1030
testb $0x1, 0x2d51(%rip)      # 0x40a0
je 0x1353
jmp 0x1372
leaq 0xced(%rip), %rdi       # 0x2047
leaq 0xcbb(%rip), %rsi       # 0x201c
movl $0x20, %edx
leaq 0xcbf(%rip), %rcx       # 0x202c
callq 0x1070
movb $0x0, 0x2d27(%rip)      # 0x40a0
movl $0x11, %edi
callq 0x1030
testb $0x1, 0x2d16(%rip)      # 0x40a0
jne 0x138e
jmp 0x13ad
leaq 0xcb1(%rip), %rdi       # 0x2046
leaq 0xc80(%rip), %rsi       # 0x201c
movl $0x23, %edx
leaq 0xc84(%rip), %rcx       # 0x202c
callq 0x1070
movl $0x4000, %edi           # imm = 0x4000
callq 0x10c0
movq %rax, -0x30(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x4000, -0x20(%rbp)    # imm = 0x4000
movq -0x30(%rbp), %rsi
leaq 0xc7b(%rip), %rdi       # 0x2050
movb $0x0, %al
callq 0x1060
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10f0
cmpl $0x0, %eax
jge 0x1401
movl $0x1, %edi
leaq 0xc63(%rip), %rsi       # 0x205d
movb $0x0, %al
callq 0x10b0
leaq 0xc61(%rip), %rdi       # 0x2069
movb $0x0, %al
callq 0x1060
leaq -0x12(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x1438
movl $0x1, %edi
leaq 0xc49(%rip), %rsi       # 0x207a
movb $0x0, %al
callq 0x10b0
cmpl $0x1, -0x18(%rbp)
jne 0x1464
leaq -0x12(%rbp), %rdi
leaq -0x12(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x1100
movl $0x1, %edi
leaq 0xc1f(%rip), %rsi       # 0x207c
movb $0x0, %al
callq 0x10b0
movq 0x2c3d(%rip), %rax      # 0x40a8
movq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x1488
movq 0x2c2d(%rip), %rax      # 0x40a8
movq -0x30(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jb 0x148a
jmp 0x14a9
leaq 0xbf1(%rip), %rdi       # 0x2082
leaq 0xb84(%rip), %rsi       # 0x201c
movl $0x32, %edx
leaq 0xb88(%rip), %rcx       # 0x202c
callq 0x1070
leaq -0xc8(%rbp), %rdi
leaq 0x2889(%rip), %rsi      # 0x3d40
movl $0x98, %edx
callq 0x10a0
movl $0x2, %edi
leaq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1050
cmpl $0x0, %eax
jge 0x14ee
movl $0x1, %edi
leaq 0xbe8(%rip), %rsi       # 0x20cf
movb $0x0, %al
callq 0x10b0
movl $0x2, %edi
callq 0x1030
movq 0x2ba9(%rip), %rsi      # 0x40a8
movq -0x30(%rbp), %rdx
movq -0x30(%rbp), %rcx
addq -0x20(%rbp), %rcx
leaq 0xbc7(%rip), %rdi       # 0x20d9
movb $0x0, %al
callq 0x1060
movq 0x2b88(%rip), %rax      # 0x40a8
movq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x152b
jmp 0x154a
leaq 0xbbe(%rip), %rdi       # 0x20f0
leaq 0xae3(%rip), %rsi       # 0x201c
movl $0x3a, %edx
leaq 0xae7(%rip), %rcx       # 0x202c
callq 0x1070
movq 0x2b57(%rip), %rax      # 0x40a8
movq -0x30(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jae 0x1560
jmp 0x157f
leaq 0xba8(%rip), %rdi       # 0x210f
leaq 0xaae(%rip), %rsi       # 0x201c
movl $0x3b, %edx
leaq 0xab2(%rip), %rcx       # 0x202c
callq 0x1070
leaq -0x12(%rbp), %rdi
callq 0x1040
cmpl $0x0, %eax
jge 0x15a4
leaq -0x12(%rbp), %rdx
movl $0x1, %edi
leaq 0xb9d(%rip), %rsi       # 0x213a
movb $0x0, %al
callq 0x10b0
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbp
retq
nop