void custom_sighandler(int signum) {
  printf(1, "User-defined handler called!\n");
  static int i = 0;
  int *ret = &i;
  i++;
  if (i == 100) {
    ret += 55;
    (*ret) = (*ret) + 8;
    printf(1, "%x", *ret);
  }
}


x86 assembly (clang, -O0):
<custom_sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1,%edi
lea    0xed9(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x2ef7(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2eed(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ee4(%rip)
cmpl   $0x64,0x2edd(%rip)
jne    118b <custom_sighandler+0x7b>
mov    -0x10(%rbp),%rax
add    $0xdc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x8,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    $0x1,%edi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<custom_sighandler>:
push   %rax
lea    0xee8(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2f02(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ef9(%rip)
cmp    $0x64,%eax
jne    115b <custom_sighandler+0x4b>
mov    0x2fca(%rip),%edx
add    $0x8,%edx
mov    %edx,0x2fc1(%rip)
lea    0xed0(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
pop    %rcx
jmp    1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [30 x i8] c"User-defined handler called!\0A\00"
@custom_sighandler.i = internal global i32 0
@.str.1 = [3 x i8] c"%x\00"
define void @custom_sighandler(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32* @custom_sighandler.i, i32** %3
%5 = load i32, i32* @custom_sighandler.i
%6 = add nsw i32 %5, 1
store i32 %6, i32* @custom_sighandler.i
%7 = load i32, i32* @custom_sighandler.i
%8 = icmp eq i32 %7, 100
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 55
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 8
%15 = load i32*, i32** %3
store i32 %14, i32* %15
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %9, %1
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"User-defined handler called!\0A\00"
@custom_sighandler.i = internal unnamed_addr global i32 0
@.str.1 = [3 x i8] c"%x\00"
define void @custom_sighandler(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @custom_sighandler.i
%4 = add nsw i32 %3, 1
store i32 %4, i32* @custom_sighandler.i
%5 = icmp eq i32 %4, 100
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* getelementptr inbounds (i32, i32* @custom_sighandler.i, i64 55)
%8 = add nsw i32 %7, 8
store i32 %8, i32* getelementptr inbounds (i32, i32* @custom_sighandler.i, i64 55)
%9 = tail call i32 (i8*, ...) @printf(i8* inttoptr (i64 1 to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %1
ret void
}