#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 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*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockdesc, port, n;
  char *buffer;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  int tlen;
  buffer = argv[3];
  port = atoi(argv[2]);
  sockdesc = socket(AF_INET, SOCK_STREAM, 0);
  if (sockdesc < 0)
    perror("socket error");
  server = gethostbyname(argv[1]);
  if (server == NULL) {
    fprintf(stderr, "wrong host\n");
    exit(0);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(port);
  if (connect(sockdesc, &serv_addr, sizeof(serv_addr)) < 0)
    perror("connection error");
  n = write(sockdesc, buffer, strlen(buffer));
  tlen = strlen(buffer);
  if (tlen <= 140) {
    if (n < 0)
      perror("socket write error");
    bzero(buffer, 140);
    n = read(sockdesc, buffer, 140);
    printf("%s\n", buffer);
  } else
    (perror("ERROR: twit above 140 characters!!!"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1244 <main+0x64>
lea    0xdc1(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    127c <main+0x9c>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bcopy@plt>
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    12e3 <main+0x103>
lea    0xd3b(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x8c,-0x44(%rbp)
jg     1371 <main+0x191>
cmpl   $0x0,-0x1c(%rbp)
jge    133a <main+0x15a>
lea    0xcf5(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    $0x8c,%esi
call   10c0 <bzero@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x8c,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xcd6(%rip),%rdi
call   1060 <printf@plt>
jmp    137d <main+0x19d>
lea    0xcc9(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
mov    0x18(%rsi),%rbx
call   10d0 <atoi@plt>
mov    %eax,%r14d
mov    0x2de0(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
js     12ef <main+0x10f>
mov    0x8(%rbp),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     132d <main+0x14d>
mov    %rax,%rbp
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbp),%rsi
lea    0xc(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10a0 <memmove@plt>
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     1300 <main+0x120>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x8c,%eax
jg     1311 <main+0x131>
test   %ebp,%ebp
js     131f <main+0x13f>
mov    %rbx,%rdi
mov    $0x8c,%esi
call   10c0 <bzero@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x8c,%edx
call   1070 <read@plt>
lea    0xd67(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0a(%rip),%rdi
call   10b0 <perror@plt>
jmp    1227 <main+0x47>
lea    0xd12(%rip),%rdi
call   10b0 <perror@plt>
jmp    1288 <main+0xa8>
lea    0xd29(%rip),%rdi
call   10b0 <perror@plt>
jmp    12de <main+0xfe>
lea    0xd04(%rip),%rdi
call   10b0 <perror@plt>
jmp    12b2 <main+0xd2>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
lea    0xcd0(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"wrong host\0A\00"
@.str.2 = [17 x i8] c"connection error\00"
@.str.3 = [19 x i8] c"socket write error\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [36 x i8] c"ERROR: twit above 140 characters!!!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 3
%15 = load i8*, i8** %14
store i8* %15, i8** %9
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call %struct.hostent* @gethostbyname(i8* %30)
store %struct.hostent* %31, %struct.hostent** %11
%32 = load %struct.hostent*, %struct.hostent** %11
%33 = icmp eq %struct.hostent* %32, null
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %27
%39 = bitcast %struct.sockaddr_in* %10 to i8*
%40 = call i32 @bzero(i8* %39, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %41, i32* %42
%43 = load %struct.hostent*, %struct.hostent** %11
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = inttoptr i64 %45 to i8*
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = bitcast i32* %48 to i8*
%50 = load %struct.hostent*, %struct.hostent** %11
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @bcopy(i8* %46, i8* %49, i32 %52)
%54 = load i32, i32* %7
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* %6
%58 = call i64 @connect(i32 %57, %struct.sockaddr_in* %10, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %38
%61 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %38
%63 = load i32, i32* %6
%64 = load i8*, i8** %9
%65 = load i8*, i8** %9
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @write(i32 %63, i8* %64, i32 %66)
store i32 %67, i32* %8
%68 = load i8*, i8** %9
%69 = call i32 @strlen(i8* %68)
store i32 %69, i32* %12
%70 = load i32, i32* %12
%71 = icmp sle i32 %70, 140
br i1 %71, label %72, label %85
72: ; preds = %62
%73 = load i32, i32* %8
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %72
%78 = load i8*, i8** %9
%79 = call i32 @bzero(i8* %78, i32 140)
%80 = load i32, i32* %6
%81 = load i8*, i8** %9
%82 = call i32 @read(i32 %80, i8* %81, i32 140)
store i32 %82, i32* %8
%83 = load i8*, i8** %9
%84 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %83)
br label %87
85: ; preds = %62
%86 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %77
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"wrong host\0A\00"
@.str.2 = [17 x i8] c"connection error\00"
@.str.3 = [19 x i8] c"socket write error\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [36 x i8] c"ERROR: twit above 140 characters!!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call %struct.hostent* @gethostbyname(i8* %18)
%20 = icmp eq %struct.hostent* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %16
%26 = call i32 @bzero(i8* %4, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i64 0, i32 1
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%33 = bitcast i32* %32 to i8*
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i64 0, i32 0
%35 = load i32, i32* %34
%36 = tail call i32 @htons(i32 %9)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %36, i32* %37
%38 = call i64 @connect(i32 %12, %struct.sockaddr_in* %3, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %25
%41 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %25
%43 = call i32 @strlen(i8* %6)
%44 = call i32 @write(i32 %12, i8* %6, i32 %43)
%45 = call i32 @strlen(i8* %6)
%46 = icmp slt i32 %45, 141
br i1 %46, label %47, label %55
47: ; preds = %42
%48 = icmp slt i32 %44, 0
br i1 %48, label %49, label %51
49: ; preds = %47
%50 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = call i32 @bzero(i8* %6, i32 140)
%53 = call i32 @read(i32 %12, i8* %6, i32 140)
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %57
55: ; preds = %42
%56 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %51
ret i32 0
}