#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*/ desc;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ LOG_PERROR;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ get_redirect_rule(char *, int, int /*<<< orphan*/, char *, int,
                             unsigned short *, char *, int,
                             int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ init_redirect();
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];
  unsigned short iport;
  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;
  }
  list_rules();
  if (get_redirect_rule("xl1", 4662, IPPROTO_TCP, buf, 32, &iport, desc,
                        sizeof(desc), &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);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
lea    0xe60(%rip),%rdi
call   1080 <openlog@plt>
mov    $0x0,%al
call   1030 <init_redirect@plt>
cmp    $0x0,%rax
jge    11d7 <main+0x77>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <main+0x10e>
mov    $0x0,%al
call   1070 <list_rules@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
lea    -0x70(%rbp),%r11
lea    0xe2e(%rip),%rdi
mov    $0x1236,%esi
mov    $0x20,%r8d
lea    -0x72(%rbp),%r9
lea    -0x78(%rbp),%r10
lea    -0x7c(%rbp),%rax
mov    %r11,(%rsp)
movl   $0x40,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <get_redirect_rule@plt>
cmp    $0x0,%rax
jge    1245 <main+0xe5>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <main+0x107>
lea    -0x30(%rbp),%rsi
movzwl -0x72(%rbp),%edx
lea    -0x70(%rbp),%rcx
mov    -0x78(%rbp),%r8d
mov    -0x7c(%rbp),%r9d
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
call   1090 <openlog@plt>
xor    %eax,%eax
call   1040 <init_redirect@plt>
test   %rax,%rax
js     122a <main+0xba>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <list_rules@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0x30(%rsp),%r11
lea    0xe4d(%rip),%rdi
lea    0x10(%rsp),%rcx
lea    0x6(%rsp),%r9
mov    $0x1236,%esi
mov    $0x20,%r8d
push   %rax
push   %r10
push   $0x40
push   %r11
call   1070 <get_redirect_rule@plt>
add    $0x20,%rsp
test   %rax,%rax
js     1246 <main+0xd6>
movzwl 0x6(%rsp),%edx
mov    0xc(%rsp),%r8d
mov    0x8(%rsp),%r9d
lea    0xe11(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x30(%rsp),%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1252 <main+0xe2>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    1252 <main+0xe2>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
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"xl1\00"
@IPPROTO_TCP = global i32 0
@.str.3 = [28 x i8] c"get_redirect_rule() failed\0A\00"
@.str.4 = [37 x i8] c"\0A%s:%d '%s' packets=%llu bytes=%llu\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 i16
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* @LOG_PERROR
%12 = load i32, i32* @LOG_USER
%13 = call i32 @openlog(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i64 (...) @init_redirect()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %37
19: ; preds = %2
%20 = call i32 (...) @list_rules()
%21 = load i32, i32* @IPPROTO_TCP
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = call i64 @get_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4662, i32 %21, i8* %22, i32 32, i16* %8, i8* %23, i32 64, i32* %9, i32* %10)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %36
28: ; preds = %19
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%30 = load i16, i16* %8
%31 = zext i16 %30 to i32
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %29, i32 %31, i8* %32, i32 %33, i32 %34)
br label %36
36: ; preds = %28, %26
store i32 0, i32* %3
br label %37
37: ; preds = %36, %16
%38 = load i32, i32* %3
ret i32 %38
}

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"xl1\00"
@IPPROTO_TCP = global i32 0
@.str.4 = [37 x i8] c"\0A%s:%d '%s' packets=%llu bytes=%llu\0A\00"
@str = [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 i16
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = bitcast i16* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%13 = load i32, i32* @LOG_PERROR
%14 = load i32, i32* @LOG_USER
%15 = tail call i32 @openlog(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail 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 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %34
21: ; preds = %2
%22 = tail call i32 (...) @list_rules()
%23 = load i32, i32* @IPPROTO_TCP
%24 = call i64 @get_redirect_rule(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4662, i32 %23, i8* %8, i32 32, i16* %5, i8* %9, i32 64, i32* %6, i32* %7)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %34
28: ; preds = %21
%29 = load i16, i16* %5
%30 = zext i16 %29 to i32
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %8, i32 %30, i8* %9, i32 %31, i32 %32)
br label %34
34: ; preds = %26, %28, %18
%35 = phi i32 [ 1, %18 ], [ 0, %28 ], [ 0, %26 ]
ret i32 %35
}