#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 */
typedef struct TYPE_11__ TYPE_2__;
typedef struct TYPE_10__ TYPE_1__;

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_name;
};
struct TYPE_11__ {
  scalar_t__ id_num;
  int /*<<< orphan*/ ctl_addr;
  int /*<<< orphan*/ r_tty;
  int /*<<< orphan*/ r_name;
};
struct TYPE_10__ {
  int answer;
  void *id_num;
};
typedef TYPE_1__ CTL_RESPONSE;
typedef TYPE_2__ CTL_MSG;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int MACHINE_UNKNOWN;
int SUCCESS;
void *announce(TYPE_2__ *, int /*<<< orphan*/);
TYPE_2__ *find_request(TYPE_2__ *);
int find_user(int /*<<< orphan*/, int /*<<< orphan*/);
struct hostent *gethostbyaddr(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void *htonl(scalar_t__);
int /*<<< orphan*/ insert_table(TYPE_2__ *, TYPE_1__ *);
scalar_t__ new_id();
void do_announce(CTL_MSG *mp, CTL_RESPONSE *rp) {
  struct hostent *hp;
  CTL_MSG *ptr;
  int result;
  result = find_user(mp->r_name, mp->r_tty);
  if (result != SUCCESS) {
    rp->answer = result;
    return;
  }
  hp = gethostbyaddr(&((struct sockaddr_in *)(void *)(&mp->ctl_addr))->sin_addr,
                     sizeof(struct in_addr), AF_INET);
  if (hp == (struct hostent *)0) {
    rp->answer = MACHINE_UNKNOWN;
    return;
  }
  ptr = find_request(mp);
  if (ptr == (CTL_MSG *)0) {
    insert_table(mp, rp);
    rp->answer = announce(mp, hp->h_name);
    return;
  }
  if (mp->id_num > ptr->id_num) {
    ptr->id_num = new_id();
    rp->id_num = htonl(ptr->id_num);
    rp->answer = announce(mp, hp->h_name);
  } else {
    rp->id_num = htonl(ptr->id_num);
    rp->answer = SUCCESS;
  }
}


x86 assembly (clang, -O0):
<do_announce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
call   1080 <find_user@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
je     11b6 <do_announce+0x46>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b3 <do_announce+0x143>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <gethostbyaddr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f4 <do_announce+0x84>
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b3 <do_announce+0x143>
mov    -0x8(%rbp),%rdi
call   1040 <find_request@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1235 <do_announce+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <insert_table@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <announce@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b3 <do_announce+0x143>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jle    128d <do_announce+0x11d>
mov    $0x0,%al
call   1060 <new_id@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <htonl@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <announce@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12b3 <do_announce+0x143>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <htonl@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2d4d(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_announce>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0xc(%rdi),%esi
mov    0x10(%rdi),%edi
call   1080 <find_user@plt>
mov    0x2e67(%rip),%r13
cmp    0x0(%r13),%eax
jne    121b <do_announce+0xab>
lea    0x8(%rbx),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <gethostbyaddr@plt>
test   %rax,%rax
je     11eb <do_announce+0x7b>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <find_request@plt>
test   %rax,%rax
je     11f6 <do_announce+0x86>
mov    %rax,%r12
mov    (%rax),%rdi
cmp    %rdi,(%rbx)
jle    120e <do_announce+0x9e>
xor    %eax,%eax
call   1060 <new_id@plt>
mov    %rax,(%r12)
mov    %rax,%rdi
call   1050 <htonl@plt>
mov    %rax,0x8(%r14)
jmp    1201 <do_announce+0x91>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
jmp    121b <do_announce+0xab>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <insert_table@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <announce@plt>
jmp    121b <do_announce+0xab>
call   1050 <htonl@plt>
mov    %rax,0x8(%r14)
mov    0x0(%r13),%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_11__ = type { i64, i32, i32, i32 }
%struct.TYPE_10__ = type { i32, i8* }
%struct.hostent = type { i32 }
%struct.sockaddr_in = type { i32 }
@SUCCESS = global i32 0
@AF_INET = global i32 0
@MACHINE_UNKNOWN = global i32 0
define void @do_announce(%struct.TYPE_11__* %0, %struct.TYPE_10__* %1) {
%3 = alloca %struct.TYPE_11__*
%4 = alloca %struct.TYPE_10__*
%5 = alloca %struct.hostent*
%6 = alloca %struct.TYPE_11__*
%7 = alloca i32
store %struct.TYPE_11__* %0, %struct.TYPE_11__** %3
store %struct.TYPE_10__* %1, %struct.TYPE_10__** %4
%8 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%9 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %8, i32 0, i32 3
%10 = load i32, i32* %9
%11 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%12 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %11, i32 0, i32 2
%13 = load i32, i32* %12
%14 = call i32 @find_user(i32 %10, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = load i32, i32* @SUCCESS
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* %7
%20 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%21 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %20, i32 0, i32 0
store i32 %19, i32* %21
br label %89
22: ; preds = %2
%23 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%24 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %23, i32 0, i32 1
%25 = bitcast i32* %24 to i8*
%26 = bitcast i8* %25 to %struct.sockaddr_in*
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %26, i32 0, i32 0
%28 = load i32, i32* @AF_INET
%29 = call %struct.hostent* @gethostbyaddr(i32* %27, i32 4, i32 %28)
store %struct.hostent* %29, %struct.hostent** %5
%30 = load %struct.hostent*, %struct.hostent** %5
%31 = icmp eq %struct.hostent* %30, null
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = load i32, i32* @MACHINE_UNKNOWN
%34 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%35 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %34, i32 0, i32 0
store i32 %33, i32* %35
br label %89
36: ; preds = %22
%37 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%38 = call %struct.TYPE_11__* @find_request(%struct.TYPE_11__* %37)
store %struct.TYPE_11__* %38, %struct.TYPE_11__** %6
%39 = load %struct.TYPE_11__*, %struct.TYPE_11__** %6
%40 = icmp eq %struct.TYPE_11__* %39, null
br i1 %40, label %41, label %53
41: ; preds = %36
%42 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%43 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%44 = call i32 @insert_table(%struct.TYPE_11__* %42, %struct.TYPE_10__* %43)
%45 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%46 = load %struct.hostent*, %struct.hostent** %5
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i8* @announce(%struct.TYPE_11__* %45, i32 %48)
%50 = ptrtoint i8* %49 to i32
%51 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%52 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %51, i32 0, i32 0
store i32 %50, i32* %52
br label %89
53: ; preds = %36
%54 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%55 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %54, i32 0, i32 0
%56 = load i64, i64* %55
%57 = load %struct.TYPE_11__*, %struct.TYPE_11__** %6
%58 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = icmp sgt i64 %56, %59
br i1 %60, label %61, label %79
61: ; preds = %53
%62 = call i64 (...) @new_id()
%63 = load %struct.TYPE_11__*, %struct.TYPE_11__** %6
%64 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %63, i32 0, i32 0
store i64 %62, i64* %64
%65 = load %struct.TYPE_11__*, %struct.TYPE_11__** %6
%66 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = call i8* @htonl(i64 %67)
%69 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%70 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %69, i32 0, i32 1
store i8* %68, i8** %70
%71 = load %struct.TYPE_11__*, %struct.TYPE_11__** %3
%72 = load %struct.hostent*, %struct.hostent** %5
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i8* @announce(%struct.TYPE_11__* %71, i32 %74)
%76 = ptrtoint i8* %75 to i32
%77 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%78 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %77, i32 0, i32 0
store i32 %76, i32* %78
br label %89
79: ; preds = %53
%80 = load %struct.TYPE_11__*, %struct.TYPE_11__** %6
%81 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %80, i32 0, i32 0
%82 = load i64, i64* %81
%83 = call i8* @htonl(i64 %82)
%84 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%85 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %84, i32 0, i32 1
store i8* %83, i8** %85
%86 = load i32, i32* @SUCCESS
%87 = load %struct.TYPE_10__*, %struct.TYPE_10__** %4
%88 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %87, i32 0, i32 0
store i32 %86, i32* %88
br label %89
89: ; preds = %18, %32, %41, %79, %61
ret void
}

LLVM IR (-O2):
%struct.TYPE_11__ = type { i64, i32, i32, i32 }
%struct.TYPE_10__ = type { i32, i8* }
%struct.hostent = type { i32 }
@SUCCESS = global i32 0
@AF_INET = global i32 0
@MACHINE_UNKNOWN = global i32 0
define void @do_announce(%struct.TYPE_11__* %0, %struct.TYPE_10__* %1) {
%3 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %0, i64 0, i32 3
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %0, i64 0, i32 2
%6 = load i32, i32* %5
%7 = tail call i32 @find_user(i32 %4, i32 %6)
%8 = load i32, i32* @SUCCESS
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %46
10: ; preds = %2
%11 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %0, i64 0, i32 1
%12 = load i32, i32* @AF_INET
%13 = tail call %struct.hostent* @gethostbyaddr(i32* %11, i32 4, i32 %12)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* @MACHINE_UNKNOWN
br label %46
17: ; preds = %10
%18 = tail call %struct.TYPE_11__* @find_request(%struct.TYPE_11__* %0)
%19 = icmp eq %struct.TYPE_11__* %18, null
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = tail call i32 @insert_table(%struct.TYPE_11__* %0, %struct.TYPE_10__* %1)
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%23 = load i32, i32* %22
%24 = tail call i8* @announce(%struct.TYPE_11__* %0, i32 %23)
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
br label %46
27: ; preds = %17
%28 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %0, i64 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %18, i64 0, i32 0
%31 = load i64, i64* %30
%32 = icmp sgt i64 %29, %31
br i1 %32, label %33, label %42
33: ; preds = %27
%34 = tail call i64 (...) @new_id()
store i64 %34, i64* %30
%35 = tail call i8* @htonl(i64 %34)
%36 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 1
store i8* %35, i8** %36
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%38 = load i32, i32* %37
%39 = tail call i8* @announce(%struct.TYPE_11__* %0, i32 %38)
%40 = ptrtoint i8* %39 to i64
%41 = trunc i64 %40 to i32
br label %46
42: ; preds = %27
%43 = tail call i8* @htonl(i64 %31)
%44 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 1
store i8* %43, i8** %44
%45 = load i32, i32* @SUCCESS
br label %46
46: ; preds = %2, %33, %42, %20, %15
%47 = phi i32 [ %41, %33 ], [ %45, %42 ], [ %26, %20 ], [ %16, %15 ], [ %7, %2 ]
%48 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %1, i64 0, i32 0
store i32 %47, i32* %48
ret void
}