#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ XFRM_POLICY_IN;
int /*<<< orphan*/ XFRM_POLICY_OUT;
int /*<<< orphan*/ gen_spi(struct in_addr);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/, int);
scalar_t__ xfrm_policy_add(int, int /*<<< orphan*/, int /*<<< orphan*/,
                           struct in_addr, struct in_addr, int /*<<< orphan*/,
                           struct in_addr, struct in_addr, int /*<<< orphan*/);
int xfrm_prepare(int xfrm_sock, uint32_t *seq, struct in_addr src,
                 struct in_addr dst, struct in_addr tunsrc,
                 struct in_addr tundst, uint8_t proto) {
  if (xfrm_policy_add(xfrm_sock, (*seq)++, gen_spi(src), src, dst,
                      XFRM_POLICY_OUT, tunsrc, tundst, proto)) {
    ksft_print_msg("%d[%u] "
                   "Failed to add xfrm policy"
                   "\n",
                   getpid(), 1170);
    return -1;
  }
  if (xfrm_policy_add(xfrm_sock, (*seq)++, gen_spi(src), dst, src,
                      XFRM_POLICY_IN, tunsrc, tundst, proto)) {
    ksft_print_msg("%d[%u] "
                   "Failed to add xfrm policy"
                   "\n",
                   getpid(), 1176);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<xfrm_prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %edx,-0x8(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
mov    %rsi,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x34(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
mov    0x2e55(%rip),%rax
mov    (%rax),%r9d
mov    0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x18(%rbp),%r11d
mov    -0x20(%rbp),%r10d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <xfrm_policy_add@plt>
cmp    $0x0,%rax
je     11e2 <xfrm_prepare+0xa2>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe34(%rip),%rdi
mov    $0x492,%edx
call   1050 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <xfrm_prepare+0x12b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x3c(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
mov    0x2dcb(%rip),%rax
mov    (%rax),%r9d
mov    0x10(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0x18(%rbp),%r11d
mov    -0x20(%rbp),%r10d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <xfrm_policy_add@plt>
cmp    $0x0,%rax
je     1264 <xfrm_prepare+0x124>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xdb2(%rip),%rdi
mov    $0x498,%edx
call   1050 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <xfrm_prepare+0x12b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfrm_prepare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8,0x8(%rsp)
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%r15d
mov    (%rsi),%ebp
lea    0x1(%rbp),%eax
mov    %eax,(%rsi)
mov    %edx,%edi
call   1040 <gen_spi@plt>
mov    0x2e69(%rip),%rcx
mov    (%rcx),%r9d
sub    $0x8,%rsp
mov    %r15d,0x8(%rsp)
mov    %r15d,%edi
mov    %r14d,%r15d
mov    %ebp,%esi
mov    %eax,%edx
mov    %r14d,%ecx
mov    %r13d,0xc(%rsp)
mov    %r13d,%r8d
mov    0x58(%rsp),%r13d
push   %r13
mov    %r12,0x20(%rsp)
push   %r12
push   0x20(%rsp)
call   1060 <xfrm_policy_add@plt>
add    $0x20,%rsp
mov    $0x492,%r14d
test   %rax,%rax
jne    1208 <xfrm_prepare+0xc8>
mov    (%rbx),%ebp
lea    0x1(%rbp),%eax
mov    %eax,(%rbx)
mov    %r15d,%edi
call   1040 <gen_spi@plt>
mov    0x2e04(%rip),%rcx
mov    (%rcx),%r9d
sub    $0x8,%rsp
mov    0x8(%rsp),%edi
mov    %ebp,%esi
mov    %eax,%edx
mov    0xc(%rsp),%ecx
mov    %r15d,%r8d
push   %r13
push   0x20(%rsp)
push   0x20(%rsp)
call   1060 <xfrm_policy_add@plt>
add    $0x20,%rsp
mov    $0x498,%r14d
test   %rax,%rax
je     1234 <xfrm_prepare+0xf4>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdea(%rip),%rdi
mov    %eax,%esi
mov    %r14d,%edx
call   1050 <ksft_print_msg@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1225 <xfrm_prepare+0xe5>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@XFRM_POLICY_OUT = global i32 0
@.str = [34 x i8] c"%d[%u] Failed to add xfrm policy\0A\00"
@XFRM_POLICY_IN = global i32 0
define i32 @xfrm_prepare(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca %struct.in_addr
%10 = alloca %struct.in_addr
%11 = alloca %struct.in_addr
%12 = alloca %struct.in_addr
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
store i32 %2, i32* %16
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
store i32 %3, i32* %17
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
store i32 %4, i32* %18
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i32 0, i32 0
store i32 %5, i32* %19
store i32 %0, i32* %13
store i32* %1, i32** %14
store i32 %6, i32* %15
%20 = load i32, i32* %13
%21 = load i32*, i32** %14
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @gen_spi(i32 %25)
%27 = load i32, i32* @XFRM_POLICY_OUT
%28 = load i32, i32* %15
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @xfrm_policy_add(i32 %20, i32 %22, i32 %26, i32 %30, i32 %32, i32 %27, i32 %34, i32 %36, i32 %28)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %7
%40 = call i32 (...) @getpid()
%41 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %40, i32 1170)
store i32 -1, i32* %8
br label %66
42: ; preds = %7
%43 = load i32, i32* %13
%44 = load i32*, i32** %14
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %44
%47 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @gen_spi(i32 %48)
%50 = load i32, i32* @XFRM_POLICY_IN
%51 = load i32, i32* %15
%52 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i64 @xfrm_policy_add(i32 %43, i32 %45, i32 %49, i32 %53, i32 %55, i32 %50, i32 %57, i32 %59, i32 %51)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %42
%63 = call i32 (...) @getpid()
%64 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %63, i32 1176)
store i32 -1, i32* %8
br label %66
65: ; preds = %42
store i32 0, i32* %8
br label %66
66: ; preds = %65, %62, %39
%67 = load i32, i32* %8
ret i32 %67
}

LLVM IR (-O2):
@XFRM_POLICY_OUT = global i32 0
@.str = [34 x i8] c"%d[%u] Failed to add xfrm policy\0A\00"
@XFRM_POLICY_IN = global i32 0
define i32 @xfrm_prepare(i32 %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
%10 = tail call i32 @gen_spi(i32 %2)
%11 = load i32, i32* @XFRM_POLICY_OUT
%12 = tail call i64 @xfrm_policy_add(i32 %0, i32 %8, i32 %10, i32 %2, i32 %3, i32 %11, i32 %4, i32 %5, i32 %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
%17 = tail call i32 @gen_spi(i32 %2)
%18 = load i32, i32* @XFRM_POLICY_IN
%19 = tail call i64 @xfrm_policy_add(i32 %0, i32 %15, i32 %17, i32 %3, i32 %2, i32 %18, i32 %4, i32 %5, i32 %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %14, %7
%22 = phi i32 [ 1170, %7 ], [ 1176, %14 ]
%23 = tail call i32 (...) @getpid()
%24 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %22)
br label %25
25: ; preds = %21, %14
%26 = phi i32 [ 0, %14 ], [ -1, %21 ]
ret i32 %26
}