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

/* Variables and functions */
int /*<<< orphan*/ getpid();
scalar_t__ ip4_addr_set(int, int /*<<< orphan*/, char *, struct in_addr, int);
scalar_t__ ip4_route_set(int, int /*<<< orphan*/, char *, struct in_addr,
                         struct in_addr);
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/, int);
int tunnel_set_route(int route_sock, uint32_t *route_seq, char *veth,
                     struct in_addr tunsrc, struct in_addr tundst) {
  if (ip4_addr_set(route_sock, (*route_seq)++, "lo", tunsrc, 30)) {
    ksft_print_msg("%d[%u] "
                   "Failed to set ipv4 addr"
                   "\n",
                   getpid(), 431);
    return -1;
  }
  if (ip4_route_set(route_sock, (*route_seq)++, veth, tunsrc, tundst)) {
    ksft_print_msg("%d[%u] "
                   "Failed to set ipv4 route"
                   "\n",
                   getpid(), 436);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tunnel_set_route>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %ecx,-0x8(%rbp)
mov    %r8d,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    %esi,%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
lea    0xe8c(%rip),%rdx
mov    $0x1e,%r8d
call   1050 <ip4_addr_set@plt>
cmp    $0x0,%rax
je     11af <tunnel_set_route+0x6f>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x1af,%edx
call   1060 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <tunnel_set_route+0xc6>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    %esi,%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1030 <ip4_route_set@plt>
cmp    $0x0,%rax
je     11ff <tunnel_set_route+0xbf>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe3a(%rip),%rdi
mov    $0x1b4,%edx
call   1060 <ksft_print_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <tunnel_set_route+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tunnel_set_route>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
mov    (%rsi),%esi
lea    0x1(%rsi),%eax
mov    %eax,0x0(%rbp)
lea    0xe9b(%rip),%rdx
mov    $0x1e,%r8d
call   1050 <ip4_addr_set@plt>
test   %rax,%rax
je     118c <tunnel_set_route+0x4c>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
mov    $0x1af,%edx
jmp    11bf <tunnel_set_route+0x7f>
mov    0x0(%rbp),%esi
lea    0x1(%rsi),%eax
mov    %eax,0x0(%rbp)
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r12d,%ecx
mov    %r14d,%r8d
call   1030 <ip4_route_set@plt>
test   %rax,%rax
je     11d2 <tunnel_set_route+0x92>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
mov    $0x1b4,%edx
call   1060 <ksft_print_msg@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    11c9 <tunnel_set_route+0x89>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [3 x i8] c"lo\00"
@.str.1 = [32 x i8] c"%d[%u] Failed to set ipv4 addr\0A\00"
@.str.2 = [33 x i8] c"%d[%u] Failed to set ipv4 route\0A\00"
define i32 @tunnel_set_route(i32 %0, i32* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.in_addr
%8 = alloca %struct.in_addr
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i32 %3, i32* %12
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %4, i32* %13
store i32 %0, i32* %9
store i32* %1, i32** %10
store i8* %2, i8** %11
%14 = load i32, i32* %9
%15 = load i32*, i32** %10
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @ip4_addr_set(i32 %14, i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19, i32 30)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = call i32 (...) @getpid()
%24 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 431)
store i32 -1, i32* %6
br label %41
25: ; preds = %5
%26 = load i32, i32* %9
%27 = load i32*, i32** %10
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %27
%30 = load i8*, i8** %11
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @ip4_route_set(i32 %26, i32 %28, i8* %30, i32 %32, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %25
%38 = call i32 (...) @getpid()
%39 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 436)
store i32 -1, i32* %6
br label %41
40: ; preds = %25
store i32 0, i32* %6
br label %41
41: ; preds = %40, %37, %22
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"lo\00"
@.str.1 = [32 x i8] c"%d[%u] Failed to set ipv4 addr\0A\00"
@.str.2 = [33 x i8] c"%d[%u] Failed to set ipv4 route\0A\00"
define i32 @tunnel_set_route(i32 %0, i32* nocapture %1, i8* %2, i32 %3, i32 %4) {
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
store i32 %7, i32* %1
%8 = tail call i64 @ip4_addr_set(i32 %0, i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3, i32 30)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 431)
br label %21
13: ; preds = %5
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
%16 = tail call i64 @ip4_route_set(i32 %0, i32 %14, i8* %2, i32 %3, i32 %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 436)
br label %21
21: ; preds = %13, %18, %10
%22 = phi i32 [ -1, %10 ], [ -1, %18 ], [ 0, %13 ]
ret i32 %22
}