#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa_dest;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bzero(char *, int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stuff_net_addr(int /*<<< orphan*/ *, char *);
void setup_transmit(int usd, char *host, short port) {
  struct sockaddr_in sa_dest;
  bzero((char *)&sa_dest, sizeof(sa_dest));
  sa_dest.sin_family = AF_INET;
  stuff_net_addr(&(sa_dest.sin_addr), host);
  sa_dest.sin_port = htons(port);
  if (connect(usd, (struct sockaddr *)&sa_dest, sizeof(sa_dest)) == -1) {
    perror("connect");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<setup_transmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
call   1080 <stuff_net_addr@plt>
movswl -0x12(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    11dd <setup_transmit+0x7d>
lea    0xe32(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_transmit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1050 <bzero@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <stuff_net_addr@plt>
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
je     11c9 <setup_transmit+0x69>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe30(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [8 x i8] c"connect\00"
define void @setup_transmit(i32 %0, i8* %1, i16 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i16
%7 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i8* %1, i8** %5
store i16 %2, i16* %6
%8 = bitcast %struct.sockaddr_in* %7 to i8*
%9 = call i32 @bzero(i8* %8, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%13 = load i8*, i8** %5
%14 = call i32 @stuff_net_addr(i32* %12, i8* %13)
%15 = load i16, i16* %6
%16 = call i32 @htons(i16 signext %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %4
%19 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%20 = call i32 @connect(i32 %18, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [8 x i8] c"connect\00"
define void @setup_transmit(i32 %0, i8* %1, i16 signext %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = call i32 @bzero(i8* %5, i32 12)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%10 = call i32 @stuff_net_addr(i32* %9, i8* %1)
%11 = call i32 @htons(i16 signext %2)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %11, i32* %12
%13 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%14 = call i32 @connect(i32 %0, %struct.sockaddr* %13, i32 12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
ret void
}