#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 tcb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ decode_fprog(struct tcb *, unsigned short, unsigned long);
int /*<<< orphan*/ tprintf(char *, unsigned long);
int /*<<< orphan*/ tprints(char *);
scalar_t__ umoven(struct tcb *, unsigned long, int, void *);
void print_seccomp_filter(struct tcb *tcp, unsigned long addr) {
  if (addr) {
    struct {
      unsigned short len;
      unsigned long filter;
    } fprog;
    if (umoven((tcp), (addr), sizeof(*(&fprog)), (void *)(&fprog)) < 0)
      tprintf("%#lx", addr);
    else
      decode_fprog(tcp, fprog.len, fprog.filter);
  } else {
    tprints("NULL");
  }
}


x86 assembly (clang, -O0):
<print_seccomp_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a9 <print_seccomp_filter+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rcx
mov    $0x10,%edx
call   1030 <umoven@plt>
cmp    $0x0,%rax
jge    1190 <print_seccomp_filter+0x50>
mov    -0x10(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1040 <tprintf@plt>
jmp    11a4 <print_seccomp_filter+0x64>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%ax
mov    -0x18(%rbp),%rdx
movzwl %ax,%esi
call   1050 <decode_fprog@plt>
jmp    11b5 <print_seccomp_filter+0x75>
lea    0xe55(%rip),%rdi
call   1060 <tprints@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_seccomp_filter>:
test   %rsi,%rsi
je     117a <print_seccomp_filter+0x3a>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rcx
mov    $0x10,%edx
call   1030 <umoven@plt>
test   %rax,%rax
js     1186 <print_seccomp_filter+0x46>
movzwl 0x8(%rsp),%esi
mov    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1050 <decode_fprog@plt>
jmp    1195 <print_seccomp_filter+0x55>
lea    0xe84(%rip),%rdi
jmp    1060 <tprints@plt>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
call   1040 <tprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tcb = type { i32 }
%struct.anon = type { i16, i64 }
@.str = [5 x i8] c"%#lx\00"
@.str.1 = [5 x i8] c"NULL\00"
define void @print_seccomp_filter(%struct.tcb* %0, i64 %1) {
%3 = alloca %struct.tcb*
%4 = alloca i64
%5 = alloca %struct.anon
store %struct.tcb* %0, %struct.tcb** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = load %struct.tcb*, %struct.tcb** %3
%10 = load i64, i64* %4
%11 = bitcast %struct.anon* %5 to i8*
%12 = call i64 @umoven(%struct.tcb* %9, i64 %10, i32 16, i8* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i64, i64* %4
%16 = call i32 @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %24
17: ; preds = %8
%18 = load %struct.tcb*, %struct.tcb** %3
%19 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 0
%20 = load i16, i16* %19
%21 = getelementptr inbounds %struct.anon, %struct.anon* %5, i32 0, i32 1
%22 = load i64, i64* %21
%23 = call i32 @decode_fprog(%struct.tcb* %18, i16 zeroext %20, i64 %22)
br label %24
24: ; preds = %17, %14
br label %27
25: ; preds = %2
%26 = call i32 @tprints(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %24
ret void
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
%struct.anon = type { i16, i64 }
@.str = [5 x i8] c"%#lx\00"
@.str.1 = [5 x i8] c"NULL\00"
define void @print_seccomp_filter(%struct.tcb* %0, i64 %1) {
%3 = alloca %struct.anon
%4 = icmp eq i64 %1, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = bitcast %struct.anon* %3 to i8*
%7 = call i64 @umoven(%struct.tcb* %0, i64 %1, i32 16, i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @tprintf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %17
11: ; preds = %5
%12 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 0
%13 = load i16, i16* %12
%14 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 1
%15 = load i64, i64* %14
%16 = call i32 @decode_fprog(%struct.tcb* %0, i16 zeroext %13, i64 %15)
br label %17
17: ; preds = %11, %9
br label %20
18: ; preds = %2
%19 = tail call i32 @tprints(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %17
ret void
}