#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 uint16_t;
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stun_test(char *, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void print_stun_probe(char *server, uint16_t sport, uint16_t tunport) {
  char *address;
  struct hostent *hp;
  printf("STUN on %s:%u\n", server, sport);
  srand(time(NULL));
  hp = gethostbyname(server);
  if (!hp)
    return;
  address = inet_ntoa(*(struct in_addr *)hp->h_addr_list[0]);
  stun_test(address, sport, tunport);
}


x86 assembly (clang, -O0):
<print_stun_probe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    -0x8(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <print_stun_probe+0x52>
jmp    11d6 <print_stun_probe+0x76>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1080 <stun_test@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stun_probe>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11b6 <print_stun_probe+0x56>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <stun_test@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [15 x i8] c"STUN on %s:%u\0A\00"
define void @print_stun_probe(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.hostent*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
%14 = load i8*, i8** %4
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %8
%16 = load %struct.hostent*, %struct.hostent** %8
%17 = icmp ne %struct.hostent* %16, null
br i1 %17, label %19, label %18
18: ; preds = %3
br label %33
19: ; preds = %3
%20 = load %struct.hostent*, %struct.hostent** %8
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 0
%22 = load i64*, i64** %21
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to %struct.in_addr*
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i8* @inet_ntoa(i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i32 @stun_test(i8* %29, i32 %30, i32 %31)
br label %33
33: ; preds = %19, %18
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [15 x i8] c"STUN on %s:%u\0A\00"
define void @print_stun_probe(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call %struct.hostent* @gethostbyname(i8* %0)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %18, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%11 = load i64*, i64** %10
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to %struct.in_addr*
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %13, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i8* @inet_ntoa(i32 %15)
%17 = tail call i32 @stun_test(i8* %16, i32 %1, i32 %2)
br label %18
18: ; preds = %3, %9
ret void
}