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

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


x86 assembly (clang, -O0):
<print_stun_probe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%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    -0x10(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c0 <print_stun_probe+0x60>
xor    %eax,%eax
mov    0x2e2a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <print_stun_probe+0x87>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1080 <stun_test@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stun_probe>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0xe89(%rip),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %rbp,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11c4 <print_stun_probe+0x64>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <stun_test@plt>
mov    0x2e15(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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"
@EIO = global i32 0
define i32 @print_stun_probe(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.hostent*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
%13 = call i32 @time(i32* null)
%14 = call i32 @srand(i32 %13)
%15 = load i8*, i8** %5
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %9
%17 = load %struct.hostent*, %struct.hostent** %9
%18 = icmp ne %struct.hostent* %17, null
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* @EIO
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %36
22: ; preds = %3
%23 = load %struct.hostent*, %struct.hostent** %9
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i64*, i64** %24
%26 = getelementptr inbounds i64, i64* %25, i64 0
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to %struct.in_addr*
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i8* @inet_ntoa(i32 %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @stun_test(i8* %32, i32 %33, i32 %34)
store i32 %35, i32* %4
br label %36
36: ; preds = %22, %19
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [15 x i8] c"STUN on %s:%u\0A\00"
@EIO = global i32 0
define i32 @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 %9, label %12
9: ; preds = %3
%10 = load i32, i32* @EIO
%11 = sub nsw i32 0, %10
br label %21
12: ; preds = %3
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%14 = load i64*, i64** %13
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to %struct.in_addr*
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i8* @inet_ntoa(i32 %18)
%20 = tail call i32 @stun_test(i8* %19, i32 %1, i32 %2)
br label %21
21: ; preds = %12, %9
%22 = phi i32 [ %20, %12 ], [ %11, %9 ]
ret i32 %22
}