#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 uid_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
unsigned long get_inode_by_ipport(unsigned long, unsigned short);
scalar_t__ get_pid_by_inode(unsigned long);
int get_uid_by_pid(scalar_t__);
uid_t get_uid_by_ipport(unsigned long ip, unsigned short int rport) {
  unsigned long inode;
  pid_t pid = 0;
  uid_t uid = -1;
  inode = get_inode_by_ipport(ip, rport);
  if (inode == 0) {
    return uid;
  }
  pid = get_pid_by_inode(inode);
  if (pid == 0) {
    return uid;
  }
  uid = get_uid_by_pid(pid);
  return uid;
}


x86 assembly (clang, -O0):
<get_uid_by_ipport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movzwl -0x12(%rbp),%esi
call   1040 <get_inode_by_ipport@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1179 <get_uid_by_ipport+0x49>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <get_uid_by_ipport+0x7e>
mov    -0x20(%rbp),%rdi
call   1050 <get_pid_by_inode@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119c <get_uid_by_ipport+0x6c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <get_uid_by_ipport+0x7e>
mov    -0x28(%rbp),%rdi
call   1030 <get_uid_by_pid@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uid_by_ipport>:
push   %rax
call   1040 <get_inode_by_ipport@plt>
test   %rax,%rax
je     1151 <get_uid_by_ipport+0x21>
mov    %rax,%rdi
call   1050 <get_pid_by_inode@plt>
test   %rax,%rax
je     1151 <get_uid_by_ipport+0x21>
mov    %rax,%rdi
pop    %rax
jmp    1030 <get_uid_by_pid@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @get_uid_by_ipport(i64 %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i16
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i64 %0, i64* %4
store i16 %1, i16* %5
store i64 0, i64* %7
store i32 -1, i32* %8
%9 = load i64, i64* %4
%10 = load i16, i16* %5
%11 = call i64 @get_inode_by_ipport(i64 %9, i16 zeroext %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %8
store i32 %15, i32* %3
br label %27
16: ; preds = %2
%17 = load i64, i64* %6
%18 = call i64 @get_pid_by_inode(i64 %17)
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %8
store i32 %22, i32* %3
br label %27
23: ; preds = %16
%24 = load i64, i64* %7
%25 = call i32 @get_uid_by_pid(i64 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %21, %14
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @get_uid_by_ipport(i64 %0, i16 zeroext %1) {
%3 = tail call i64 @get_inode_by_ipport(i64 %0, i16 zeroext %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i64 @get_pid_by_inode(i64 %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @get_uid_by_pid(i64 %6)
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ %9, %8 ], [ -1, %2 ], [ -1, %5 ]
ret i32 %11
}