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

/* Variables and functions */
int /*<<< orphan*/ gen_spi(struct in_addr);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/, int);
int xfrm_state_add(int, int /*<<< orphan*/, int /*<<< orphan*/, struct in_addr,
                   struct in_addr, struct xfrm_desc *);
int xfrm_state_check(int, int /*<<< orphan*/, int /*<<< orphan*/,
                     struct in_addr, struct in_addr, struct xfrm_desc *);
int xfrm_set(int xfrm_sock, uint32_t *seq, struct in_addr src,
             struct in_addr dst, struct in_addr tunsrc, struct in_addr tundst,
             struct xfrm_desc *desc) {
  int err;
  err = xfrm_state_add(xfrm_sock, (*seq)++, gen_spi(src), src, dst, desc);
  if (err) {
    ksft_print_msg("%d[%u] "
                   "Failed to add xfrm state"
                   "\n",
                   getpid(), 1087);
    return -1;
  }
  err = xfrm_state_add(xfrm_sock, (*seq)++, gen_spi(src), dst, src, desc);
  if (err) {
    ksft_print_msg("%d[%u] "
                   "Failed to add xfrm state"
                   "\n",
                   getpid(), 1093);
    return -1;
  }
  err = xfrm_state_check(xfrm_sock, (*seq)++, gen_spi(src), src, dst, desc);
  err |= xfrm_state_check(xfrm_sock, (*seq)++, gen_spi(src), dst, src, desc);
  if (err) {
    ksft_print_msg("%d[%u] "
                   "Failed to check xfrm state"
                   "\n",
                   getpid(), 1101);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<xfrm_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
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,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x38(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    %eax,%edx
mov    0x10(%rbp),%r9
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1060 <xfrm_state_add@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11d8 <xfrm_set+0x88>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe3e(%rip),%rdi
mov    $0x43f,%edx
call   1070 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e7 <xfrm_set+0x197>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x40(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    %eax,%edx
mov    0x10(%rbp),%r9
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%r8d
call   1060 <xfrm_state_add@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     123f <xfrm_set+0xef>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xdd7(%rip),%rdi
mov    $0x445,%edx
call   1070 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e7 <xfrm_set+0x197>
mov    -0x24(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x50(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%esi
mov    %eax,%edx
mov    0x10(%rbp),%r9
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1050 <xfrm_state_check@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    %ecx,-0x48(%rbp)
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <gen_spi@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    %eax,%edx
mov    0x10(%rbp),%r9
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%r8d
call   1050 <xfrm_state_check@plt>
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12e0 <xfrm_set+0x190>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xd57(%rip),%rdi
mov    $0x44d,%edx
call   1070 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e7 <xfrm_set+0x197>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfrm_set>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %edi,%r12d
mov    0x40(%rsp),%r14
mov    (%rsi),%ebx
lea    0x1(%rbx),%eax
mov    %eax,(%rsi)
mov    %edx,%edi
call   1040 <gen_spi@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %eax,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %r14,%r9
call   1060 <xfrm_state_add@plt>
test   %eax,%eax
je     11ad <xfrm_set+0x5d>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe5f(%rip),%rdi
mov    %eax,%esi
mov    $0x43f,%edx
jmp    1259 <xfrm_set+0x109>
mov    0x0(%rbp),%ebx
lea    0x1(%rbx),%eax
mov    %eax,0x0(%rbp)
mov    %r13d,%edi
call   1040 <gen_spi@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %eax,%edx
mov    %r15d,%ecx
mov    %r13d,%r8d
mov    %r14,%r9
call   1060 <xfrm_state_add@plt>
test   %eax,%eax
je     11ee <xfrm_set+0x9e>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
mov    $0x445,%edx
jmp    1259 <xfrm_set+0x109>
mov    0x0(%rbp),%ebx
lea    0x1(%rbx),%eax
mov    %eax,0x0(%rbp)
mov    %r13d,%edi
call   1040 <gen_spi@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %eax,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %r14,%r9
call   1050 <xfrm_state_check@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%rbp),%ebx
lea    0x1(%rbx),%eax
mov    %eax,0x0(%rbp)
mov    %r13d,%edi
call   1040 <gen_spi@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %eax,%edx
mov    %r15d,%ecx
mov    %r13d,%r8d
mov    %r14,%r9
call   1050 <xfrm_state_check@plt>
or     0x4(%rsp),%eax
je     1272 <xfrm_set+0x122>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdcf(%rip),%rdi
mov    %eax,%esi
mov    $0x44d,%edx
call   1070 <ksft_print_msg@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1263 <xfrm_set+0x113>

LLVM IR (-O0):
%struct.xfrm_desc = type { i32 }
%struct.in_addr = type { i32 }
@.str = [33 x i8] c"%d[%u] Failed to add xfrm state\0A\00"
@.str.1 = [35 x i8] c"%d[%u] Failed to check xfrm state\0A\00"
define i32 @xfrm_set(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, %struct.xfrm_desc* %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 %struct.xfrm_desc*
%16 = alloca i32
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
store i32 %2, i32* %17
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
store i32 %3, i32* %18
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
store i32 %4, i32* %19
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i32 0, i32 0
store i32 %5, i32* %20
store i32 %0, i32* %13
store i32* %1, i32** %14
store %struct.xfrm_desc* %6, %struct.xfrm_desc** %15
%21 = load i32, i32* %13
%22 = load i32*, i32** %14
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @gen_spi(i32 %26)
%28 = load %struct.xfrm_desc*, %struct.xfrm_desc** %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 = call i32 @xfrm_state_add(i32 %21, i32 %23, i32 %27, i32 %30, i32 %32, %struct.xfrm_desc* %28)
store i32 %33, i32* %16
%34 = load i32, i32* %16
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %7
%37 = call i32 (...) @getpid()
%38 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %37, i32 1087)
store i32 -1, i32* %8
br label %93
39: ; preds = %7
%40 = load i32, i32* %13
%41 = load i32*, i32** %14
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
%44 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @gen_spi(i32 %45)
%47 = load %struct.xfrm_desc*, %struct.xfrm_desc** %15
%48 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @xfrm_state_add(i32 %40, i32 %42, i32 %46, i32 %49, i32 %51, %struct.xfrm_desc* %47)
store i32 %52, i32* %16
%53 = load i32, i32* %16
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %39
%56 = call i32 (...) @getpid()
%57 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %56, i32 1093)
store i32 -1, i32* %8
br label %93
58: ; preds = %39
%59 = load i32, i32* %13
%60 = load i32*, i32** %14
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
store i32 %62, i32* %60
%63 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i32 @gen_spi(i32 %64)
%66 = load %struct.xfrm_desc*, %struct.xfrm_desc** %15
%67 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @xfrm_state_check(i32 %59, i32 %61, i32 %65, i32 %68, i32 %70, %struct.xfrm_desc* %66)
store i32 %71, i32* %16
%72 = load i32, i32* %13
%73 = load i32*, i32** %14
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1
store i32 %75, i32* %73
%76 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 @gen_spi(i32 %77)
%79 = load %struct.xfrm_desc*, %struct.xfrm_desc** %15
%80 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%81 = load i32, i32* %80
%82 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%83 = load i32, i32* %82
%84 = call i32 @xfrm_state_check(i32 %72, i32 %74, i32 %78, i32 %81, i32 %83, %struct.xfrm_desc* %79)
%85 = load i32, i32* %16
%86 = or i32 %85, %84
store i32 %86, i32* %16
%87 = load i32, i32* %16
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %58
%90 = call i32 (...) @getpid()
%91 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %90, i32 1101)
store i32 -1, i32* %8
br label %93
92: ; preds = %58
store i32 0, i32* %8
br label %93
93: ; preds = %92, %89, %55, %36
%94 = load i32, i32* %8
ret i32 %94
}

LLVM IR (-O2):
%struct.xfrm_desc = type { i32 }
@.str = [33 x i8] c"%d[%u] Failed to add xfrm state\0A\00"
@.str.1 = [35 x i8] c"%d[%u] Failed to check xfrm state\0A\00"
define i32 @xfrm_set(i32 %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, %struct.xfrm_desc* %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 = tail call i32 @xfrm_state_add(i32 %0, i32 %8, i32 %10, i32 %2, i32 %3, %struct.xfrm_desc* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %14, i32 1087)
br label %39
16: ; preds = %7
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
%19 = tail call i32 @gen_spi(i32 %2)
%20 = tail call i32 @xfrm_state_add(i32 %0, i32 %17, i32 %19, i32 %3, i32 %2, %struct.xfrm_desc* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = tail call i32 (...) @getpid()
%24 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %23, i32 1093)
br label %39
25: ; preds = %16
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
%28 = tail call i32 @gen_spi(i32 %2)
%29 = tail call i32 @xfrm_state_check(i32 %0, i32 %26, i32 %28, i32 %2, i32 %3, %struct.xfrm_desc* %6)
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
%32 = tail call i32 @gen_spi(i32 %2)
%33 = tail call i32 @xfrm_state_check(i32 %0, i32 %30, i32 %32, i32 %3, i32 %2, %struct.xfrm_desc* %6)
%34 = or i32 %33, %29
%35 = icmp eq i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %25
%37 = tail call i32 (...) @getpid()
%38 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 1101)
br label %39
39: ; preds = %25, %36, %22, %13
%40 = phi i32 [ -1, %13 ], [ -1, %22 ], [ -1, %36 ], [ 0, %25 ]
ret i32 %40
}