#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct sigaction {
  int sa_flags;
  int /*<<< orphan*/ sa_handler;
  int /*<<< orphan*/ sa_sigaction;
  int /*<<< orphan*/ sa_mask;
};
typedef int /*<<< orphan*/ sigbuf;
typedef int /*<<< orphan*/ handlerbuf;
typedef int /*<<< orphan*/ flagsbuf;

/* Variables and functions */
int SA_SIGINFO;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/
call_lookup_bitmask_by_class(char *, int, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ latrace_struct_to_str_sigset_t(int /*<<< orphan*/ *, char *,
                                                  int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
int latrace_struct_to_str_sigaction(struct sigaction *obj, char *buf,
                                    size_t blen) {
  char sigbuf[512];
  char flagsbuf[128];
  char handlerbuf[128];
  if (obj == NULL)
    return -1;
  memset(flagsbuf, 0, sizeof(flagsbuf));
  memset(sigbuf, 0, sizeof(sigbuf));
  memset(handlerbuf, 0, sizeof(handlerbuf));
  call_lookup_bitmask_by_class("sa_flag", obj->sa_flags, NULL, flagsbuf,
                               sizeof(flagsbuf));
  latrace_struct_to_str_sigset_t(&obj->sa_mask, sigbuf, sizeof(sigbuf));
  if (obj->sa_flags & SA_SIGINFO)
    snprintf(handlerbuf, sizeof(handlerbuf), "sigaction=%p", obj->sa_sigaction);
  else {
    if (obj->sa_handler == SIG_IGN)
      snprintf(handlerbuf, sizeof(handlerbuf), "handler=SIG_IGN");
    else if (obj->sa_handler == SIG_DFL)
      snprintf(handlerbuf, sizeof(handlerbuf), "handler=SIG_DFL");
    else
      snprintf(handlerbuf, sizeof(handlerbuf), "handler=%p", obj->sa_handler);
  }
  snprintf(buf, blen, "[%s, flags=%s, mask=%s]", handlerbuf, flagsbuf, sigbuf);
  return 0;
}


x86 assembly (clang, -O0):
<latrace_struct_to_str_sigaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <latrace_struct_to_str_sigaction+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e8 <latrace_struct_to_str_sigaction+0x1a8>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    -0x2a0(%rbp),%rcx
lea    0xe45(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x80,%r8d
call   1060 <call_lookup_bitmask_by_class@plt>
mov    -0x10(%rbp),%rdi
add    $0xc,%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1030 <latrace_struct_to_str_sigset_t@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2de0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1221 <latrace_struct_to_str_sigaction+0xe1>
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    $0x80,%esi
lea    0xdf3(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12b6 <latrace_struct_to_str_sigaction+0x176>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
jne    1256 <latrace_struct_to_str_sigaction+0x116>
lea    -0x320(%rbp),%rdi
mov    $0x80,%esi
lea    0xdcb(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12b1 <latrace_struct_to_str_sigaction+0x171>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d74(%rip),%rcx
cmp    (%rcx),%eax
jne    128b <latrace_struct_to_str_sigaction+0x14b>
lea    -0x320(%rbp),%rdi
mov    $0x80,%esi
lea    0xda6(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12ac <latrace_struct_to_str_sigaction+0x16c>
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    $0x80,%esi
lea    0xd90(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12b1 <latrace_struct_to_str_sigaction+0x171>
jmp    12b6 <latrace_struct_to_str_sigaction+0x176>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x320(%rbp),%rcx
lea    -0x2a0(%rbp),%r8
lea    -0x220(%rbp),%r9
lea    0xd66(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latrace_struct_to_str_sigaction>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x300,%rsp
test   %rdi,%rdi
je     121a <latrace_struct_to_str_sigaction+0xda>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x80(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0x100(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    (%rbx),%esi
lea    0xe58(%rip),%rdi
xor    %edx,%edx
mov    %r12,%rcx
mov    $0x80,%r8d
call   1060 <call_lookup_bitmask_by_class@plt>
lea    0xc(%rbx),%rdi
mov    %r13,%rsi
mov    $0x200,%edx
call   1030 <latrace_struct_to_str_sigset_t@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rbx)
je     1232 <latrace_struct_to_str_sigaction+0xf2>
mov    0x8(%rbx),%ecx
lea    0xe28(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe4a(%rip),%rdx
xor    %ebx,%ebx
mov    %rsp,%rcx
lea    0x80(%rsp),%r8
lea    0x100(%rsp),%r9
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    121f <latrace_struct_to_str_sigaction+0xdf>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x300,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x4(%rbx),%ecx
mov    0x2dac(%rip),%rax
cmp    (%rax),%ecx
jne    124d <latrace_struct_to_str_sigaction+0x10d>
movups 0xdce(%rip),%xmm0
movaps %xmm0,(%rsp)
jmp    11ef <latrace_struct_to_str_sigaction+0xaf>
mov    0x2d84(%rip),%rax
cmp    (%rax),%ecx
jne    1265 <latrace_struct_to_str_sigaction+0x125>
movups 0xdc6(%rip),%xmm0
movaps %xmm0,(%rsp)
jmp    11ef <latrace_struct_to_str_sigaction+0xaf>
lea    0xdc9(%rip),%rdx
jmp    11e0 <latrace_struct_to_str_sigaction+0xa0>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i32, i32 }
@.str = [8 x i8] c"sa_flag\00"
@SA_SIGINFO = global i32 0
@.str.1 = [13 x i8] c"sigaction=%p\00"
@SIG_IGN = global i32 0
@.str.2 = [16 x i8] c"handler=SIG_IGN\00"
@SIG_DFL = global i32 0
@.str.3 = [16 x i8] c"handler=SIG_DFL\00"
@.str.4 = [11 x i8] c"handler=%p\00"
@.str.5 = [24 x i8] c"[%s, flags=%s, mask=%s]\00"
define i32 @latrace_struct_to_str_sigaction(%struct.sigaction* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.sigaction*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [512 x i8]
%9 = alloca [128 x i8]
%10 = alloca [128 x i8]
store %struct.sigaction* %0, %struct.sigaction** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load %struct.sigaction*, %struct.sigaction** %5
%12 = icmp eq %struct.sigaction* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %75
14: ; preds = %3
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 128)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 512)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 128)
%21 = load %struct.sigaction*, %struct.sigaction** %5
%22 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%25 = call i32 @call_lookup_bitmask_by_class(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %23, i32* null, i8* %24, i32 128)
%26 = load %struct.sigaction*, %struct.sigaction** %5
%27 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %26, i32 0, i32 3
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%29 = call i32 @latrace_struct_to_str_sigset_t(i32* %27, i8* %28, i32 512)
%30 = load %struct.sigaction*, %struct.sigaction** %5
%31 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* @SA_SIGINFO
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %14
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%38 = load %struct.sigaction*, %struct.sigaction** %5
%39 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %37, i64 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %68
42: ; preds = %14
%43 = load %struct.sigaction*, %struct.sigaction** %5
%44 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = load i32, i32* @SIG_IGN
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%50 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %49, i64 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %67
51: ; preds = %42
%52 = load %struct.sigaction*, %struct.sigaction** %5
%53 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = load i32, i32* @SIG_DFL
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%59 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %58, i64 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %66
60: ; preds = %51
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%62 = load %struct.sigaction*, %struct.sigaction** %5
%63 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %62, i32 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %61, i64 128, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %60, %57
br label %67
67: ; preds = %66, %48
br label %68
68: ; preds = %67, %36
%69 = load i8*, i8** %6
%70 = load i64, i64* %7
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%72 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%74 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %69, i64 %70, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %71, i8* %72, i8* %73)
store i32 0, i32* %4
br label %75
75: ; preds = %68, %13
%76 = load i32, i32* %4
ret i32 %76
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i32, i32 }
@.str = [8 x i8] c"sa_flag\00"
@SA_SIGINFO = global i32 0
@.str.1 = [13 x i8] c"sigaction=%p\00"
@SIG_IGN = global i32 0
@.str.2 = [16 x i8] c"handler=SIG_IGN\00"
@SIG_DFL = global i32 0
@.str.3 = [16 x i8] c"handler=SIG_DFL\00"
@.str.4 = [11 x i8] c"handler=%p\00"
@.str.5 = [24 x i8] c"[%s, flags=%s, mask=%s]\00"
define i32 @latrace_struct_to_str_sigaction(%struct.sigaction* %0, i8* nocapture writeonly %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = icmp eq %struct.sigaction* %0, null
br i1 %10, label %42, label %11
11: ; preds = %3
%12 = call i32 @memset(i8* %8, i32 0, i32 128)
%13 = call i32 @memset(i8* %7, i32 0, i32 512)
%14 = call i32 @memset(i8* %9, i32 0, i32 128)
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @call_lookup_bitmask_by_class(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %16, i32* null, i8* %8, i32 128)
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 3
%19 = call i32 @latrace_struct_to_str_sigset_t(i32* %18, i8* %7, i32 512)
%20 = load i32, i32* %15
%21 = load i32, i32* @SA_SIGINFO
%22 = and i32 %21, %20
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %11
%25 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 2
%26 = load i32, i32* %25
%27 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %40
28: ; preds = %11
%29 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 1
%30 = load i32, i32* %29
%31 = load i32, i32* @SIG_IGN
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %28
br label %40
34: ; preds = %28
%35 = load i32, i32* @SIG_DFL
%36 = icmp eq i32 %30, %35
br i1 %36, label %37, label %38
37: ; preds = %34
br label %40
38: ; preds = %34
%39 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 128, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %40
40: ; preds = %33, %38, %37, %24
%41 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %9, i8* %8, i8* %7)
br label %42
42: ; preds = %3, %40
%43 = phi i32 [ 0, %40 ], [ -1, %3 ]
ret i32 %43
}