#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*/ u_int64_t;
typedef int /*<<< orphan*/ rhost;
typedef int /*<<< orphan*/ desc;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ LOG_PERROR;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ add_redirect_rule2(char *, char *, int, char *, int,
                                      int /*<<< orphan*/, char *,
                                      int /*<<< orphan*/);
scalar_t__ delete_redirect_rule(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ get_redirect_rule(char *, int, int /*<<< orphan*/, char *, int,
                             unsigned short *, char *, int, char *, int,
                             unsigned int *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *);
scalar_t__ init_redirect();
int /*<<< orphan*/ list_eports_tcp();
int /*<<< orphan*/ list_rules();
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int arc, char **argv) {
  char buf[32];
  char desc[64];
  char rhost[64];
  unsigned short iport;
  unsigned int timestamp;
  u_int64_t packets = 0;
  u_int64_t bytes = 0;
  openlog("testobsdrdr", LOG_PERROR, LOG_USER);
  if (init_redirect() < 0) {
    fprintf(stderr, "init_redirect() failed\n");
    return 1;
  }
  add_redirect_rule2("ep0", "8.8.8.8", 12123, "192.168.1.125", 1234,
                     IPPROTO_UDP, "test description", 0);
  list_rules();
  list_eports_tcp();
  if (get_redirect_rule("xl1", 4662, IPPROTO_TCP, buf, sizeof(buf), &iport,
                        desc, sizeof(desc), rhost, sizeof(rhost), &timestamp,
                        &packets, &bytes) < 0)
    printf("get_redirect_rule() failed\n");
  else {
    printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc,
           packets, bytes);
  }
  if (delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
    printf("delete_redirect_rule() failed\n");
  else
    printf("delete_redirect_rule() succeded\n");
  if (delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
    printf("delete_redirect_rule() failed\n");
  else
    printf("delete_redirect_rule() succeded\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
movl   $0x0,-0x14(%rbp)
mov    %edi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0xcc(%rbp)
movl   $0x0,-0xd0(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
lea    0xe27(%rip),%rdi
call   10b0 <openlog@plt>
mov    $0x0,%al
call   1040 <init_redirect@plt>
cmp    $0x0,%rax
jge    1210 <main+0x80>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    13af <main+0x21f>
mov    0x2da1(%rip),%rax
mov    (%rax),%r9d
lea    0xe03(%rip),%rdi
lea    0xe00(%rip),%rsi
mov    $0x2f5b,%edx
lea    0xdfc(%rip),%rcx
mov    $0x4d2,%r8d
lea    0xdfd(%rip),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1080 <add_redirect_rule2@plt>
mov    $0x0,%al
call   10a0 <list_rules@plt>
mov    $0x0,%al
call   1030 <list_eports_tcp@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rcx
lea    -0x80(%rbp),%r14
lea    -0xc0(%rbp),%rbx
lea    0xdcd(%rip),%rdi
mov    $0x1236,%esi
mov    $0x20,%r8d
lea    -0xc2(%rbp),%r9
lea    -0xc8(%rbp),%r11
lea    -0xcc(%rbp),%r10
lea    -0xd0(%rbp),%rax
mov    %r14,(%rsp)
movl   $0x40,0x8(%rsp)
mov    %rbx,0x10(%rsp)
movl   $0x40,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1090 <get_redirect_rule@plt>
cmp    $0x0,%rax
jge    12f3 <main+0x163>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    131e <main+0x18e>
lea    -0x40(%rbp),%rsi
movzwl -0xc2(%rbp),%edx
lea    -0x80(%rbp),%rcx
mov    -0xcc(%rbp),%r8d
mov    -0xd0(%rbp),%r9d
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%edx
lea    0xcf6(%rip),%rdi
mov    $0x2f5b,%esi
call   1070 <delete_redirect_rule@plt>
cmp    $0x0,%rax
jge    1355 <main+0x1c5>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1363 <main+0x1d3>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edx
lea    0xcb1(%rip),%rdi
mov    $0x2f5b,%esi
call   1070 <delete_redirect_rule@plt>
cmp    $0x0,%rax
jge    139a <main+0x20a>
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a8 <main+0x218>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
lea    0xe2b(%rip),%rdi
call   10c0 <openlog@plt>
xor    %eax,%eax
call   1050 <init_redirect@plt>
test   %rax,%rax
js     12ba <main+0x11a>
mov    0x2dc7(%rip),%r14
mov    (%r14),%r9d
lea    0xe43(%rip),%rax
lea    0xe22(%rip),%rdi
lea    0xe1f(%rip),%rsi
lea    0xe20(%rip),%rcx
mov    $0x2f5b,%edx
mov    $0x4d2,%r8d
push   $0x0
push   %rax
call   1090 <add_redirect_rule2@plt>
add    $0x10,%rsp
xor    %eax,%eax
call   10b0 <list_rules@plt>
xor    %eax,%eax
call   1030 <list_eports_tcp@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
sub    $0x8,%rsp
lea    0xc(%rsp),%rax
lea    0x10(%rsp),%rbx
lea    0x14(%rsp),%r10
lea    0x78(%rsp),%r11
lea    0x38(%rsp),%r15
lea    0xded(%rip),%rdi
lea    0x18(%rsp),%rcx
lea    0xa(%rsp),%r9
mov    $0x1236,%esi
mov    $0x20,%r8d
push   %rax
push   %rbx
push   %r10
push   $0x40
push   %r11
push   $0x40
push   %r15
call   10a0 <get_redirect_rule@plt>
add    $0x40,%rsp
test   %rax,%rax
js     12d6 <main+0x136>
movzwl 0x2(%rsp),%edx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
lea    0xdac(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x30(%rsp),%rcx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e2 <main+0x142>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    133f <main+0x19f>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%edx
lea    0xd38(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2f5b,%esi
call   1080 <delete_redirect_rule@plt>
test   %rax,%rax
lea    0xd95(%rip),%rax
lea    0xd6e(%rip),%rdi
cmovs  %rax,%rdi
call   1040 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x2f5b,%esi
call   1080 <delete_redirect_rule@plt>
test   %rax,%rax
js     1331 <main+0x191>
lea    0xd49(%rip),%rdi
jmp    1338 <main+0x198>
lea    0xd60(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"testobsdrdr\00"
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"init_redirect() failed\0A\00"
@.str.2 = [4 x i8] c"ep0\00"
@.str.3 = [8 x i8] c"8.8.8.8\00"
@.str.4 = [14 x i8] c"192.168.1.125\00"
@IPPROTO_UDP = global i32 0
@.str.5 = [17 x i8] c"test description\00"
@.str.6 = [4 x i8] c"xl1\00"
@IPPROTO_TCP = global i32 0
@.str.7 = [28 x i8] c"get_redirect_rule() failed\0A\00"
@.str.8 = [37 x i8] c"\0A%s:%d '%s' packets=%llu bytes=%llu\0A\00"
@.str.9 = [31 x i8] c"delete_redirect_rule() failed\0A\00"
@.str.10 = [33 x i8] c"delete_redirect_rule() succeded\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca [64 x i8]
%8 = alloca [64 x i8]
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* @LOG_PERROR
%14 = load i32, i32* @LOG_USER
%15 = call i32 @openlog(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i64 (...) @init_redirect()
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %59
21: ; preds = %2
%22 = load i32, i32* @IPPROTO_UDP
%23 = call i32 @add_redirect_rule2(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 12123, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 1234, i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 0)
%24 = call i32 (...) @list_rules()
%25 = call i32 (...) @list_eports_tcp()
%26 = load i32, i32* @IPPROTO_TCP
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%30 = call i64 @get_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 4662, i32 %26, i8* %27, i32 32, i16* %9, i8* %28, i32 64, i8* %29, i32 64, i32* %10, i32* %11, i32* %12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %42
34: ; preds = %21
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%36 = load i16, i16* %9
%37 = zext i16 %36 to i32
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* %35, i32 %37, i8* %38, i32 %39, i32 %40)
br label %42
42: ; preds = %34, %32
%43 = load i32, i32* @IPPROTO_UDP
%44 = call i64 @delete_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 12123, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
br label %50
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = load i32, i32* @IPPROTO_UDP
%52 = call i64 @delete_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 12123, i32 %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
br label %58
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
store i32 0, i32* %3
br label %59
59: ; preds = %58, %18
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [12 x i8] c"testobsdrdr\00"
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"init_redirect() failed\0A\00"
@.str.2 = [4 x i8] c"ep0\00"
@.str.3 = [8 x i8] c"8.8.8.8\00"
@.str.4 = [14 x i8] c"192.168.1.125\00"
@IPPROTO_UDP = global i32 0
@.str.5 = [17 x i8] c"test description\00"
@.str.6 = [4 x i8] c"xl1\00"
@IPPROTO_TCP = global i32 0
@.str.8 = [37 x i8] c"\0A%s:%d '%s' packets=%llu bytes=%llu\0A\00"
@str.11 = [32 x i8] c"delete_redirect_rule() succeded\00"
@str.13 = [30 x i8] c"delete_redirect_rule() failed\00"
@str.14 = [27 x i8] c"get_redirect_rule() failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%13 = bitcast i16* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%16 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%17 = load i32, i32* @LOG_PERROR
%18 = load i32, i32* @LOG_USER
%19 = tail call i32 @openlog(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = tail call i64 (...) @init_redirect()
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %54
25: ; preds = %2
%26 = load i32, i32* @IPPROTO_UDP
%27 = tail call i32 @add_redirect_rule2(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 12123, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 1234, i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 0)
%28 = tail call i32 (...) @list_rules()
%29 = tail call i32 (...) @list_eports_tcp()
%30 = load i32, i32* @IPPROTO_TCP
%31 = call i64 @get_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 4662, i32 %30, i8* %10, i32 32, i16* %6, i8* %11, i32 64, i8* %12, i32 64, i32* %7, i32* %8, i32* %9)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0))
br label %41
35: ; preds = %25
%36 = load i16, i16* %6
%37 = zext i16 %36 to i32
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* %10, i32 %37, i8* %11, i32 %38, i32 %39)
br label %41
41: ; preds = %35, %33
%42 = load i32, i32* @IPPROTO_UDP
%43 = call i64 @delete_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 12123, i32 %42)
%44 = icmp slt i64 %43, 0
%45 = select i1 %44, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0)
%46 = call i32 @puts(i8* dereferenceable(1) %45)
%47 = load i32, i32* @IPPROTO_UDP
%48 = call i64 @delete_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 12123, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0))
br label %54
52: ; preds = %41
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
br label %54
54: ; preds = %50, %52, %22
%55 = phi i32 [ 1, %22 ], [ 0, %52 ], [ 0, %50 ]
ret i32 %55
}