#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ make_internet_address(char *, int, struct sockaddr_in *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
extern int make_dgram_server_socket(int portnum) {
  int sock_id = socket(PF_INET, SOCK_DGRAM, 0);
  char hostname[256];
  gethostname(hostname, 256);
  struct sockaddr_in saddr;
  make_internet_address(hostname, portnum, &saddr);
  bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr));
  return sock_id;
}


x86 assembly (clang, -O0):
<make_dgram_server_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1050 <gethostname@plt>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x118(%rbp),%rdx
call   1030 <make_internet_address@plt>
mov    -0x8(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
mov    -0x8(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dgram_server_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %edi,%r14d
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <gethostname@plt>
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1030 <make_internet_address@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <bind@plt>
mov    %ebp,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @make_dgram_server_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = call i32 @gethostname(i8* %9, i32 256)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @make_internet_address(i8* %11, i32 %12, %struct.sockaddr_in* %5)
%14 = load i32, i32* %3
%15 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%16 = call i32 @bind(i32 %14, %struct.sockaddr* %15, i32 4)
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @make_dgram_server_socket(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = call i32 @gethostname(i8* %7, i32 256)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = call i32 @make_internet_address(i8* %7, i32 %0, %struct.sockaddr_in* %3)
%11 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%12 = call i32 @bind(i32 %6, %struct.sockaddr* %11, i32 4)
ret i32 %6
}