#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 sockaddr_in {
  int sin_port;
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct servent {
  int s_port;
};
struct protoent {
  int /*<<< orphan*/ p_proto;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ in_addr_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
struct protoent *getprotobyname(char *);
struct servent *getservbyname(char *, char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *stpcpy(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf("Usage: chkmail [user name] [host address] [password]\n");
    exit(1);
  }
  char *userName = argv[1];
  char *remote = argv[2];
  char *password = argv[3];
  struct servent *sent;
  struct protoent *pent;
  int port;
  int sock;
  int result;
  in_addr_t ipadr;
  struct sockaddr_in addr;
  struct hostent *hent;
  char buf[2048];
  sent = getservbyname("pop3", "tcp");
  if (sent == NULL)
    err("getservbyname");
  port = sent->s_port;
  pent = getprotobyname("tcp");
  if (pent == NULL)
    err("getprotobyname");
  hent = gethostbyname(remote);
  if (hent == NULL) {
    err("remote do not exists");
  }
  addr.sin_family = AF_INET;
  addr.sin_port = port;
  addr.sin_addr = *((struct in_addr *)hent->h_addr);
  memset(addr.sin_zero, '\0', 8);
  sock = socket(AF_INET, SOCK_STREAM, pent->p_proto);
  if (sock < 0)
    err("socket");
  result = connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr));
  if (result < 0)
    err("connect");
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  strcpy(buf, "");
  char *msg = buf;
  msg = stpcpy(msg, "USER ");
  msg = stpcpy(msg, userName);
  msg = stpcpy(msg, "\r\n\0");
  write(sock, buf, strlen(buf));
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  strcpy(buf, "");
  msg = buf;
  msg = stpcpy(msg, "PASS ");
  msg = stpcpy(msg, password);
  msg = stpcpy(msg, "\r\n\0");
  write(sock, buf, strlen(buf));
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  strcpy(buf, "LIST\r\n");
  write(sock, buf, strlen(buf));
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  char *token;
  token = strtok(buf, "\n");
  int mailCount = 0;
  if (token != NULL) {
    mailCount++;
    while ((token = strtok(NULL, "\n")) != NULL) {
      mailCount++;
    }
  }
  printf("%d \n", mailCount - 1);
  strcpy(buf, "QUIT\r\n");
  write(sock, buf, strlen(buf));
  result = read(sock, buf, sizeof(buf));
  buf[result] = '\0';
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     123b <main+0x3b>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
lea    0xdd0(%rip),%rdi
lea    0xdce(%rip),%rsi
call   1080 <getservbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    128d <main+0x8d>
lea    0xdb7(%rip),%rdi
call   10d0 <err@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    0xd9e(%rip),%rdi
call   10e0 <getprotobyname@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12bd <main+0xbd>
lea    0xd95(%rip),%rdi
call   10d0 <err@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12e1 <main+0xe1>
lea    0xd80(%rip),%rdi
call   10d0 <err@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x60(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x54(%rbp),%edi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
mov    0x2cba(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1120 <socket@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1344 <main+0x144>
lea    0xd32(%rip),%rdi
call   10d0 <err@plt>
mov    -0x40(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x4,%edx
call   1110 <connect@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    136e <main+0x16e>
lea    0xd0f(%rip),%rdi
call   10d0 <err@plt>
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
lea    -0x860(%rbp),%rdi
lea    0xcff(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x860(%rbp),%rax
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
lea    0xcc0(%rip),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
lea    0xcae(%rip),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x8a4(%rbp)
lea    -0x860(%rbp),%rax
mov    %rax,-0x8a0(%rbp)
lea    -0x860(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x8a4(%rbp),%edi
mov    -0x8a0(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
lea    -0x860(%rbp),%rdi
lea    0xc39(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x860(%rbp),%rax
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
lea    0xc00(%rip),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x868(%rbp),%rdi
lea    0xbe8(%rip),%rsi
call   1050 <stpcpy@plt>
mov    %rax,-0x868(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x894(%rbp)
lea    -0x860(%rbp),%rax
mov    %rax,-0x890(%rbp)
lea    -0x860(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x894(%rbp),%edi
mov    -0x890(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
lea    -0x860(%rbp),%rdi
lea    0xb61(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x884(%rbp)
lea    -0x860(%rbp),%rax
mov    %rax,-0x880(%rbp)
lea    -0x860(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x884(%rbp),%edi
mov    -0x880(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
lea    -0x860(%rbp),%rdi
lea    0xae2(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x870(%rbp)
movl   $0x0,-0x874(%rbp)
cmpq   $0x0,-0x870(%rbp)
je     1628 <main+0x428>
mov    -0x874(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x874(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xaa4(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x870(%rbp)
cmp    $0x0,%rax
je     1623 <main+0x423>
mov    -0x874(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x874(%rbp)
jmp    15ee <main+0x3ee>
jmp    1628 <main+0x428>
mov    -0x874(%rbp),%esi
sub    $0x1,%esi
lea    0xa5b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x860(%rbp),%rdi
lea    0xa4b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x8b4(%rbp)
lea    -0x860(%rbp),%rax
mov    %rax,-0x8b0(%rbp)
lea    -0x860(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x8b4(%rbp),%edi
mov    -0x8b0(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x40(%rbp),%edi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10b0 <read@plt>
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
mov    -0x40(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x8c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
cmp    $0x4,%edi
jne    14f1 <main+0x2e1>
mov    0x8(%rsi),%rax
mov    %rax,(%rsp)
mov    0x10(%rsi),%rbp
mov    0x18(%rsi),%rax
mov    %rax,0x8(%rsp)
lea    0xdba(%rip),%rdi
lea    0xdb8(%rip),%rsi
call   1090 <getservbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1266 <main+0x56>
lea    0xda8(%rip),%rdi
call   10e0 <err@plt>
mov    (%rbx),%r14d
lea    0xd95(%rip),%rdi
call   10f0 <getprotobyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1289 <main+0x79>
lea    0xd93(%rip),%rdi
call   10e0 <err@plt>
mov    %rbp,%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12a5 <main+0x95>
lea    0xd86(%rip),%rdi
call   10e0 <err@plt>
mov    0x2d3c(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    %r14d,0x10(%rsp)
mov    0x0(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    (%r15),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
call   1130 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    12f4 <main+0xe4>
lea    0xd4c(%rip),%rdi
call   10e0 <err@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1120 <connect@plt>
test   %eax,%eax
jns    1316 <main+0x106>
lea    0xd31(%rip),%rdi
call   10e0 <err@plt>
lea    0x20(%rsp),%r12
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd2f(%rip),%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0x25(%rsp),%r13
movl   $0x52455355,0x20(%rsp)
52
movw   $0x20,0x24(%rsp)
mov    %r13,%rdi
mov    (%rsp),%rsi
call   1060 <stpcpy@plt>
lea    0xd33(%rip),%rbp
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movl   $0x53534150,0x20(%rsp)
53
movw   $0x20,0x24(%rsp)
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
call   1060 <stpcpy@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xc4f(%rip),%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xc0e(%rip),%rsi
mov    %r12,%rdi
call   1100 <strtok@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1482 <main+0x272>
lea    0xbf8(%rip),%rbx
nop
xor    %edi,%edi
mov    %rbx,%rsi
call   1100 <strtok@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1470 <main+0x260>
add    $0xffffffff,%ebp
lea    0xbd1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xbc6(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   10c0 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb71(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.servent = type { i32 }
%struct.protoent = type { i32 }
%struct.sockaddr_in = type { i32, i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [54 x i8] c"Usage: chkmail [user name] [host address] [password]\0A\00"
@.str.1 = [5 x i8] c"pop3\00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [14 x i8] c"getservbyname\00"
@.str.4 = [15 x i8] c"getprotobyname\00"
@.str.5 = [21 x i8] c"remote do not exists\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [1 x i8] zeroinitializer
@.str.9 = [6 x i8] c"USER \00"
@.str.10 = [4 x i8] c"\0D\0A\00\00"
@.str.11 = [6 x i8] c"PASS \00"
@.str.12 = [7 x i8] c"LIST\0D\0A\00"
@.str.13 = [2 x i8] c"\0A\00"
@.str.14 = [5 x i8] c"%d \0A\00"
@.str.15 = [7 x i8] c"QUIT\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.servent*
%10 = alloca %struct.protoent*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.sockaddr_in
%16 = alloca %struct.hostent*
%17 = alloca [2048 x i8]
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
store i8* %35, i8** %8
%36 = call %struct.servent* @getservbyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.servent* %36, %struct.servent** %9
%37 = load %struct.servent*, %struct.servent** %9
%38 = icmp eq %struct.servent* %37, null
br i1 %38, label %39, label %41
39: ; preds = %26
%40 = call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %26
%42 = load %struct.servent*, %struct.servent** %9
%43 = getelementptr inbounds %struct.servent, %struct.servent* %42, i32 0, i32 0
%44 = load i32, i32* %43
store i32 %44, i32* %11
%45 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.protoent* %45, %struct.protoent** %10
%46 = load %struct.protoent*, %struct.protoent** %10
%47 = icmp eq %struct.protoent* %46, null
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %41
%51 = load i8*, i8** %7
%52 = call %struct.hostent* @gethostbyname(i8* %51)
store %struct.hostent* %52, %struct.hostent** %16
%53 = load %struct.hostent*, %struct.hostent** %16
%54 = icmp eq %struct.hostent* %53, null
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 @err(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %50
%58 = load i32, i32* @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 3
store i32 %58, i32* %59
%60 = load i32, i32* %11
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
store i32 %60, i32* %61
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
%63 = load %struct.hostent*, %struct.hostent** %16
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 0
%65 = load i64, i64* %64
%66 = inttoptr i64 %65 to %struct.in_addr*
%67 = bitcast %struct.in_addr* %62 to i8*
%68 = bitcast %struct.in_addr* %66 to i8*
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
%70 = load i32, i32* %69
%71 = call i32 @memset(i32 %70, i8 signext 0, i32 8)
%72 = load i32, i32* @AF_INET
%73 = load i32, i32* @SOCK_STREAM
%74 = load %struct.protoent*, %struct.protoent** %10
%75 = getelementptr inbounds %struct.protoent, %struct.protoent* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 @socket(i32 %72, i32 %73, i32 %76)
store i32 %77, i32* %12
%78 = load i32, i32* %12
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %57
%81 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %80, %57
%83 = load i32, i32* %12
%84 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%85 = call i32 @connect(i32 %83, %struct.sockaddr* %84, i32 4)
store i32 %85, i32* %13
%86 = load i32, i32* %13
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @err(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %90
90: ; preds = %88, %82
%91 = load i32, i32* %12
%92 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%93 = call i32 @read(i32 %91, i8* %92, i32 2048)
store i32 %93, i32* %13
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %95
store i8 0, i8* %96
%97 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%98 = call i32 @strcpy(i8* %97, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
%99 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
store i8* %99, i8** %18
%100 = load i8*, i8** %18
%101 = call i8* @stpcpy(i8* %100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
store i8* %101, i8** %18
%102 = load i8*, i8** %18
%103 = load i8*, i8** %6
%104 = call i8* @stpcpy(i8* %102, i8* %103)
store i8* %104, i8** %18
%105 = load i8*, i8** %18
%106 = call i8* @stpcpy(i8* %105, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
store i8* %106, i8** %18
%107 = load i32, i32* %12
%108 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%109 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%110 = call i32 @strlen(i8* %109)
%111 = call i32 @write(i32 %107, i8* %108, i32 %110)
%112 = load i32, i32* %12
%113 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%114 = call i32 @read(i32 %112, i8* %113, i32 2048)
store i32 %114, i32* %13
%115 = load i32, i32* %13
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %116
store i8 0, i8* %117
%118 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%119 = call i32 @strcpy(i8* %118, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
%120 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
store i8* %120, i8** %18
%121 = load i8*, i8** %18
%122 = call i8* @stpcpy(i8* %121, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
store i8* %122, i8** %18
%123 = load i8*, i8** %18
%124 = load i8*, i8** %8
%125 = call i8* @stpcpy(i8* %123, i8* %124)
store i8* %125, i8** %18
%126 = load i8*, i8** %18
%127 = call i8* @stpcpy(i8* %126, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
store i8* %127, i8** %18
%128 = load i32, i32* %12
%129 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%130 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%131 = call i32 @strlen(i8* %130)
%132 = call i32 @write(i32 %128, i8* %129, i32 %131)
%133 = load i32, i32* %12
%134 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 2048)
store i32 %135, i32* %13
%136 = load i32, i32* %13
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %137
store i8 0, i8* %138
%139 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%140 = call i32 @strcpy(i8* %139, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%141 = load i32, i32* %12
%142 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%143 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%144 = call i32 @strlen(i8* %143)
%145 = call i32 @write(i32 %141, i8* %142, i32 %144)
%146 = load i32, i32* %12
%147 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%148 = call i32 @read(i32 %146, i8* %147, i32 2048)
store i32 %148, i32* %13
%149 = load i32, i32* %13
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %150
store i8 0, i8* %151
%152 = load i32, i32* %12
%153 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%154 = call i32 @read(i32 %152, i8* %153, i32 2048)
store i32 %154, i32* %13
%155 = load i32, i32* %13
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %156
store i8 0, i8* %157
%158 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%159 = call i8* @strtok(i8* %158, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
store i8* %159, i8** %19
store i32 0, i32* %20
%160 = load i8*, i8** %19
%161 = icmp ne i8* %160, null
br i1 %161, label %162, label %172
162: ; preds = %90
%163 = load i32, i32* %20
%164 = add nsw i32 %163, 1
store i32 %164, i32* %20
br label %165
165: ; preds = %168, %162
%166 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
store i8* %166, i8** %19
%167 = icmp ne i8* %166, null
br i1 %167, label %168, label %171
168: ; preds = %165
%169 = load i32, i32* %20
%170 = add nsw i32 %169, 1
store i32 %170, i32* %20
br label %165
171: ; preds = %165
br label %172
172: ; preds = %171, %90
%173 = load i32, i32* %20
%174 = sub nsw i32 %173, 1
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32 %174)
%176 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%177 = call i32 @strcpy(i8* %176, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%178 = load i32, i32* %12
%179 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%180 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%181 = call i32 @strlen(i8* %180)
%182 = call i32 @write(i32 %178, i8* %179, i32 %181)
%183 = load i32, i32* %12
%184 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%185 = call i32 @read(i32 %183, i8* %184, i32 2048)
store i32 %185, i32* %13
%186 = load i32, i32* %13
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 %187
store i8 0, i8* %188
%189 = load i32, i32* %12
%190 = call i32 @close(i32 %189)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.servent = type { i32 }
%struct.protoent = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str.1 = [5 x i8] c"pop3\00"
@.str.2 = [4 x i8] c"tcp\00"
@.str.3 = [14 x i8] c"getservbyname\00"
@.str.4 = [15 x i8] c"getprotobyname\00"
@.str.5 = [21 x i8] c"remote do not exists\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [1 x i8] zeroinitializer
@.str.9 = [6 x i8] c"USER \00"
@.str.10 = [4 x i8] c"\0D\0A\00\00"
@.str.11 = [6 x i8] c"PASS \00"
@.str.12 = [7 x i8] c"LIST\0D\0A\00"
@.str.13 = [2 x i8] c"\0A\00"
@.str.14 = [5 x i8] c"%d \0A\00"
@.str.15 = [7 x i8] c"QUIT\0D\0A\00"
@str = [53 x i8] c"Usage: chkmail [user name] [host address] [password]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2048 x i8]
%5 = icmp eq i32 %0, 4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = bitcast %struct.sockaddr_in* %3 to i8*
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%18 = tail call %struct.servent* @getservbyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq %struct.servent* %18, null
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = tail call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %9
%23 = getelementptr inbounds %struct.servent, %struct.servent* %18, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq %struct.protoent* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = tail call %struct.hostent* @gethostbyname(i8* %13)
%31 = icmp eq %struct.hostent* %30, null
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @err(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %37
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 0
%39 = load i64, i64* %38
%40 = inttoptr i64 %39 to i32*
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
%42 = load i32, i32* %40
store i32 %42, i32* %41
%43 = tail call i32 @memset(i32 undef, i8 signext 0, i32 8)
%44 = load i32, i32* @AF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = getelementptr inbounds %struct.protoent, %struct.protoent* %25, i64 0, i32 0
%47 = load i32, i32* %46
%48 = tail call i32 @socket(i32 %44, i32 %45, i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %34
%51 = tail call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %34
%53 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%54 = call i32 @connect(i32 %48, %struct.sockaddr* %53, i32 4)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = call i32 @err(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = call i32 @read(i32 %48, i8* %17, i32 2048)
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %60
store i8 0, i8* %61
%62 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 5
%64 = call i8* @stpcpy(i8* %63, i8* %11)
%65 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%66 = call i32 @strlen(i8* %17)
%67 = call i32 @write(i32 %48, i8* %17, i32 %66)
%68 = call i32 @read(i32 %48, i8* %17, i32 2048)
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %69
store i8 0, i8* %70
%71 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
%72 = call i8* @stpcpy(i8* %63, i8* %15)
%73 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%74 = call i32 @strlen(i8* %17)
%75 = call i32 @write(i32 %48, i8* %17, i32 %74)
%76 = call i32 @read(i32 %48, i8* %17, i32 2048)
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %77
store i8 0, i8* %78
%79 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
%80 = call i32 @strlen(i8* %17)
%81 = call i32 @write(i32 %48, i8* %17, i32 %80)
%82 = call i32 @read(i32 %48, i8* %17, i32 2048)
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %83
store i8 0, i8* %84
%85 = call i32 @read(i32 %48, i8* %17, i32 2048)
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %86
store i8 0, i8* %87
%88 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%89 = icmp eq i8* %88, null
br i1 %89, label %95, label %90
90: ; preds = %58, %90
%91 = phi i32 [ %94, %90 ], [ 1, %58 ]
%92 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%93 = icmp eq i8* %92, null
%94 = add nuw nsw i32 %91, 1
br i1 %93, label %95, label %90
95: ; preds = %90, %58
%96 = phi i32 [ 0, %58 ], [ %91, %90 ]
%97 = add nsw i32 %96, -1
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32 %97)
%99 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%100 = call i32 @strlen(i8* %17)
%101 = call i32 @write(i32 %48, i8* %17, i32 %100)
%102 = call i32 @read(i32 %48, i8* %17, i32 2048)
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %103
store i8 0, i8* %104
%105 = call i32 @close(i32 %48)
ret i32 0
}