#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bbcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bbzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int start_transmitter(char *ip_nr, char *port_nr) {
  int sockfd, portno;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  portno = atoi(port_nr);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  server = gethostbyname(ip_nr);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  bbzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bbcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
  serv_addr.sin_port = htons(portno);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR connecting");
  return sockfd;
}


x86 assembly (clang, -O0):
<start_transmitter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ee <start_transmitter+0x4e>
lea    0xe17(%rip),%rdi
call   1060 <error@plt>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1222 <start_transmitter+0x82>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bbzero@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bbcopy@plt>
mov    -0x18(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1289 <start_transmitter+0xe9>
lea    0xda6(%rip),%rdi
call   1060 <error@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_transmitter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x2e27(%rip),%r12
mov    (%r12),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e7 <start_transmitter+0x47>
lea    0xe1e(%rip),%rdi
call   1060 <error@plt>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     125a <start_transmitter+0xba>
mov    %rax,%rbp
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1070 <bbzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbp),%rdi
lea    0x4(%rsp),%rsi
mov    0x0(%rbp),%edx
call   10c0 <bbcopy@plt>
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
jns    124b <start_transmitter+0xab>
lea    0xde4(%rip),%rdi
call   1060 <error@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.2 = [17 x i8] c"ERROR connecting\00"
define i32 @start_transmitter(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @atoi(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8*, i8** %3
%20 = call %struct.hostent* @gethostbyname(i8* %19)
store %struct.hostent* %20, %struct.hostent** %8
%21 = load %struct.hostent*, %struct.hostent** %8
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %18
%28 = bitcast %struct.sockaddr_in* %7 to i8*
%29 = call i32 @bbzero(i8* %28, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %30, i32* %31
%32 = load %struct.hostent*, %struct.hostent** %8
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 1
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i8*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
%38 = bitcast i32* %37 to i8*
%39 = load %struct.hostent*, %struct.hostent** %8
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @bbcopy(i8* %35, i8* %38, i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* %5
%47 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%48 = call i64 @connect(i32 %46, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %27
%51 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %27
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.2 = [17 x i8] c"ERROR connecting\00"
define i32 @start_transmitter(i8* %0, i8* nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call i32 @atoi(i8* %1)
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = tail call %struct.hostent* @gethostbyname(i8* %0)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %12
%20 = call i32 @bbzero(i8* %4, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to i8*
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%27 = bitcast i32* %26 to i8*
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @bbcopy(i8* %25, i8* %27, i32 %29)
%31 = call i32 @htons(i32 %5)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i64 @connect(i32 %8, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %19
%37 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %19
ret i32 %8
}