// File: /workspace/github_c_makefile_star2_O1/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
pushq %rbx
subq $0xc8, %rsp
movabsq $0x58585858585873, %rax # imm = 0x58585858585873
leaq -0x18(%rbp), %rbx
movq %rax, 0x6(%rbx)
movabsq $0x58736c616e676973, %rax # imm = 0x58736C616E676973
movq %rax, (%rbx)
movq %rbx, %rdi
callq 0x10e0
movl %eax, %edi
callq 0x1090
leaq 0x313(%rip), %rsi       # 0x1570
movl $0x2, %edi
callq 0x10a0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10f0
testl %eax, %eax
js 0x13f7
cmpl $0x1, %eax
je 0x1403
leaq -0x18(%rbp), %rdi
callq 0x1040
testl %eax, %eax
js 0x1436
cmpb $0x1, 0x2e0e(%rip)      # 0x40a8
je 0x1442
movl $0x2, %edi
callq 0x1030
cmpb $0x0, 0x2df7(%rip)      # 0x40a8
je 0x1461
movb $0x0, 0x2dea(%rip)      # 0x40a8
movl $0x11, %edi
callq 0x1030
cmpb $0x1, 0x2dd9(%rip)      # 0x40a8
je 0x1480
movl $0x4000, %edi           # imm = 0x4000
callq 0x10d0
leaq -0x30(%rbp), %rbx
movq %rax, (%rbx)
movl $0x0, 0x8(%rbx)
movq $0x4000, 0x10(%rbx)     # imm = 0x4000
leaq 0xd54(%rip), %rdi       # 0x2050
movq %rax, %rsi
xorl %eax, %eax
callq 0x1070
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1100
testl %eax, %eax
js 0x149f
leaq 0xe2f(%rip), %rdi       # 0x214e
callq 0x1050
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x10f0
testl %eax, %eax
js 0x14a8
cmpl $0x1, %eax
je 0x14b1
movq 0x2d69(%rip), %rax      # 0x40b0
movq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x135d
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jb 0x1551
leaq 0x29dc(%rip), %rsi      # 0x3d40
leaq -0xc8(%rbp), %rbx
movl $0x98, %edx
movq %rbx, %rdi
callq 0x10b0
movl $0x2, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1060
testl %eax, %eax
js 0x14ca
movl $0x2, %edi
callq 0x1030
movq 0x2d10(%rip), %rsi      # 0x40b0
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
addq %rdx, %rcx
leaq 0xd0a(%rip), %rdi       # 0x20bc
xorl %eax, %eax
callq 0x1070
movq 0x2cf0(%rip), %rax      # 0x40b0
movq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x14dd
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jae 0x14fc
leaq -0x18(%rbp), %rdi
callq 0x1040
testl %eax, %eax
js 0x151b
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
leaq 0xc14(%rip), %rsi       # 0x2012
jmp 0x1522
movl $0x2, %edi
callq 0x1030
cmpb $0x0, 0x2c94(%rip)      # 0x40a8
je 0x1532
leaq -0x18(%rbp), %rdi
movq %rdi, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x1110
leaq 0xc06(%rip), %rsi       # 0x2037
jmp 0x14d1
leaq 0xbff(%rip), %rsi       # 0x203c
jmp 0x1522
leaq 0xbfd(%rip), %rdi       # 0x2046
leaq 0xbcc(%rip), %rsi       # 0x201c
leaq 0xbd5(%rip), %rcx       # 0x202c
movl $0x1e, %edx
callq 0x1080
leaq 0xbdf(%rip), %rdi       # 0x2047
leaq 0xbad(%rip), %rsi       # 0x201c
leaq 0xbb6(%rip), %rcx       # 0x202c
movl $0x20, %edx
callq 0x1080
leaq 0xbbf(%rip), %rdi       # 0x2046
leaq 0xb8e(%rip), %rsi       # 0x201c
leaq 0xb97(%rip), %rcx       # 0x202c
movl $0x23, %edx
callq 0x1080
leaq 0xcac(%rip), %rsi       # 0x2152
jmp 0x14d1
leaq 0xbae(%rip), %rsi       # 0x205d
jmp 0x14d1
leaq -0x18(%rbp), %rdi
movq %rdi, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x1110
leaq 0xb97(%rip), %rsi       # 0x205f
jmp 0x14d1
leaq 0xbe1(%rip), %rsi       # 0x20b2
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0
leaq 0xbef(%rip), %rdi       # 0x20d3
leaq 0xb31(%rip), %rsi       # 0x201c
leaq 0xb3a(%rip), %rcx       # 0x202c
movl $0x3a, %edx
callq 0x1080
leaq 0xbef(%rip), %rdi       # 0x20f2
leaq 0xb12(%rip), %rsi       # 0x201c
leaq 0xb1b(%rip), %rcx       # 0x202c
movl $0x3b, %edx
callq 0x1080
leaq 0xbfb(%rip), %rsi       # 0x211d
leaq -0x18(%rbp), %rdx
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0
leaq 0xb0e(%rip), %rdi       # 0x2047
leaq 0xadc(%rip), %rsi       # 0x201c
leaq 0xae5(%rip), %rcx       # 0x202c
movl $0x1a, %edx
callq 0x1080
leaq 0xb0d(%rip), %rdi       # 0x2065
leaq 0xabd(%rip), %rsi       # 0x201c
leaq 0xac6(%rip), %rcx       # 0x202c
movl $0x32, %edx
callq 0x1080