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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/ *);
char *get_argument(char *, int);
char *get_command(char *);
char *get_config(char *);
char *get_last_argument(char *);
char *get_prefix(char *);
char *get_username(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ join_channel(int, char *);
int /*<<< orphan*/ log_to_file(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ log_with_date(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read_line(int, char *);
int /*<<< orphan*/ send_pong(int, char *);
int /*<<< orphan*/ send_user_packet(int, char *);
int /*<<< orphan*/ set_nick(int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int main() {
  int socket_desc = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_desc == -1) {
    perror("Could not create socket");
    exit(1);
  }
  char *ip = get_config("server");
  char *port = get_config("port");
  struct sockaddr_in server;
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = AF_INET;
  server.sin_port = htons(atoi(port));
  free(ip);
  free(port);
  if (connect(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("Could not connect");
    exit(1);
  }
  char *nick = get_config("nick");
  char *channels = get_config("channels");
  set_nick(socket_desc, nick);
  send_user_packet(socket_desc, nick);
  join_channel(socket_desc, channels);
  free(nick);
  free(channels);
  FILE *logfile = fopen("bot.log.txt", "a+");
  while (1) {
    char line[512];
    read_line(socket_desc, line);
    char *prefix = get_prefix(line);
    char *username = get_username(line);
    char *command = get_command(line);
    char *argument = get_last_argument(line);
    if (strcmp(command, "PING") == 0) {
      send_pong(socket_desc, argument);
      log_with_date("Got ping. Replying with pong...");
    } else if (strcmp(command, "PRIVMSG") == 0) {
      char logline[512];
      char *channel = get_argument(line, 1);
      sprintf(logline, "%s/%s: %s", channel, username, argument);
      log_with_date(logline);
      char filename[500];
      sprintf(filename, "%s.log.txt", channel);
      freopen(filename, "a+", logfile);
      log_to_file(logline, logfile);
      free(channel);
    } else if (strcmp(command, "JOIN") == 0) {
      char logline[512];
      char *channel = get_argument(line, 1);
      sprintf(logline, "%s joined %s.", username, channel);
      log_with_date(logline);
      char filename[500];
      sprintf(filename, "%s.log.txt", channel);
      freopen(filename, "a+", logfile);
      log_to_file(logline, logfile);
      free(channel);
    } else if (strcmp(command, "PART") == 0) {
      char logline[512];
      char *channel = get_argument(line, 1);
      sprintf(logline, "%s left %s.", username, channel);
      log_with_date(logline);
      char filename[500];
      sprintf(filename, "%s.log.txt", channel);
      freopen(filename, "a+", logfile);
      log_to_file(logline, logfile);
      free(channel);
    }
    free(prefix);
    free(username);
    free(command);
    free(argument);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12de <main+0x4e>
lea    0xd31(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1180 <exit@plt>
lea    0xd33(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,-0x10(%rbp)
lea    0xd2a(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1150 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1190 <connect@plt>
cmp    $0x0,%rax
jge    136c <main+0xdc>
lea    0xcc7(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1180 <exit@plt>
lea    0xcc3(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,-0x30(%rbp)
lea    0xcb8(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1120 <set_nick@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1070 <send_user_packet@plt>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1100 <join_channel@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
lea    0xc7b(%rip),%rdi
lea    0xc80(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x240(%rbp),%rsi
call   10f0 <read_line@plt>
lea    -0x240(%rbp),%rdi
call   1080 <get_prefix@plt>
mov    %rax,-0x248(%rbp)
lea    -0x240(%rbp),%rdi
call   1050 <get_username@plt>
mov    %rax,-0x250(%rbp)
lea    -0x240(%rbp),%rdi
call   10c0 <get_command@plt>
mov    %rax,-0x258(%rbp)
lea    -0x240(%rbp),%rdi
call   1040 <get_last_argument@plt>
mov    %rax,-0x260(%rbp)
mov    -0x258(%rbp),%rdi
lea    0xc11(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    1471 <main+0x1e1>
mov    -0x8(%rbp),%edi
mov    -0x260(%rbp),%rsi
call   10a0 <send_pong@plt>
lea    0xbf1(%rip),%rdi
call   11a0 <log_with_date@plt>
jmp    16aa <main+0x41a>
mov    -0x258(%rbp),%rdi
lea    0xbf9(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    1530 <main+0x2a0>
lea    -0x240(%rbp),%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,-0x468(%rbp)
lea    -0x460(%rbp),%rdi
mov    -0x468(%rbp),%rdx
mov    -0x250(%rbp),%rcx
mov    -0x260(%rbp),%r8
lea    0xbb7(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0x460(%rbp),%rdi
call   11a0 <log_with_date@plt>
lea    -0x660(%rbp),%rdi
mov    -0x468(%rbp),%rdx
lea    0xb99(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0x660(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xb46(%rip),%rsi
call   1090 <freopen@plt>
lea    -0x460(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1140 <log_to_file@plt>
mov    -0x468(%rbp),%rdi
call   1030 <free@plt>
jmp    16a5 <main+0x415>
mov    -0x258(%rbp),%rdi
lea    0xb57(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    15e8 <main+0x358>
lea    -0x240(%rbp),%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,-0x868(%rbp)
lea    -0x860(%rbp),%rdi
mov    -0x250(%rbp),%rdx
mov    -0x868(%rbp),%rcx
lea    0xb19(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0x860(%rbp),%rdi
call   11a0 <log_with_date@plt>
lea    -0xa60(%rbp),%rdi
mov    -0x868(%rbp),%rdx
lea    0xae1(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0xa60(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xa8e(%rip),%rsi
call   1090 <freopen@plt>
lea    -0x860(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1140 <log_to_file@plt>
mov    -0x868(%rbp),%rdi
call   1030 <free@plt>
jmp    16a0 <main+0x410>
mov    -0x258(%rbp),%rdi
lea    0xab2(%rip),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
jne    169b <main+0x40b>
lea    -0x240(%rbp),%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,-0xc68(%rbp)
lea    -0xc60(%rbp),%rdi
mov    -0x250(%rbp),%rdx
mov    -0xc68(%rbp),%rcx
lea    0xa74(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0xc60(%rbp),%rdi
call   11a0 <log_with_date@plt>
lea    -0xe60(%rbp),%rdi
mov    -0xc68(%rbp),%rdx
lea    0xa29(%rip),%rsi
mov    $0x0,%al
call   1160 <sprintf@plt>
lea    -0xe60(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0x9d6(%rip),%rsi
call   1090 <freopen@plt>
lea    -0xc60(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1140 <log_to_file@plt>
mov    -0xc68(%rbp),%rdi
call   1030 <free@plt>
jmp    16a0 <main+0x410>
jmp    16a5 <main+0x415>
jmp    16aa <main+0x41a>
mov    -0x248(%rbp),%rdi
call   1030 <free@plt>
mov    -0x250(%rbp),%rdi
call   1030 <free@plt>
mov    -0x258(%rbp),%rdi
call   1030 <free@plt>
mov    -0x260(%rbp),%rdi
call   1030 <free@plt>
jmp    13d9 <main+0x149>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
mov    0x2d40(%rip),%r14
mov    (%r14),%edi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11b0 <socket@plt>
cmp    $0xffffffff,%eax
je     15d2 <main+0x342>
mov    %eax,%r15d
lea    0xd4a(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,%rbx
lea    0xd42(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   10d0 <inet_addr@plt>
mov    %eax,0x20(%rsp)
mov    (%r14),%eax
mov    %eax,0x1c(%rsp)
mov    %rbp,%rdi
call   1150 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0x18(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1190 <connect@plt>
test   %rax,%rax
js     15db <main+0x34b>
lea    0xcf9(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,%rbx
lea    0xcef(%rip),%rdi
call   10b0 <get_config@plt>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %rbx,%rsi
call   1120 <set_nick@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <send_user_packet@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1100 <join_channel@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xcb8(%rip),%rdi
lea    0xcbd(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0x230(%rsp),%rbx
lea    0xca7(%rip),%r13
mov    %r15d,%ebp
mov    %r15d,0xc(%rsp)
jmp    13f8 <main+0x168>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
call   10a0 <send_pong@plt>
lea    0xc87(%rip),%rdi
call   11a0 <log_with_date@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10f0 <read_line@plt>
mov    %rbx,%rdi
call   1080 <get_prefix@plt>
mov    %rax,0x28(%rsp)
mov    %rbx,%rdi
call   1050 <get_username@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   10c0 <get_command@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <get_last_argument@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %r13,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     13c0 <main+0x130>
mov    %r14,%rdi
lea    0xc2e(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     14b0 <main+0x220>
mov    %r14,%rdi
lea    0xc37(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     153e <main+0x2ae>
mov    %r14,%rdi
lea    0xc32(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    13d6 <main+0x146>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,%r13
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc0a(%rip),%rsi
jmp    155d <main+0x2cd>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,%rbp
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
lea    0xbb1(%rip),%rsi
mov    %rax,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    %rbx,%rdi
call   11a0 <log_with_date@plt>
lea    0x430(%rsp),%rbx
mov    %rbx,%rdi
lea    0xb91(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    %rbx,%rdi
lea    0x230(%rsp),%rbx
lea    0xb3b(%rip),%rsi
mov    0x10(%rsp),%r13
mov    %r13,%rdx
call   1090 <freopen@plt>
lea    0x30(%rsp),%rdi
mov    %r13,%rsi
lea    0xb22(%rip),%r13
call   1140 <log_to_file@plt>
mov    %rbp,%rdi
jmp    15c4 <main+0x334>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1170 <get_argument@plt>
mov    %rax,%r13
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
lea    0xb3d(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    %rbx,%rdi
call   11a0 <log_with_date@plt>
lea    0x430(%rsp),%rbx
mov    %rbx,%rdi
lea    0xb06(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1160 <sprintf@plt>
mov    %rbx,%rdi
lea    0x230(%rsp),%rbx
lea    0xab0(%rip),%rsi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   1090 <freopen@plt>
lea    0x30(%rsp),%rdi
mov    %rbp,%rsi
call   1140 <log_to_file@plt>
mov    %r13,%rdi
lea    0xa8f(%rip),%r13
mov    0xc(%rsp),%ebp
call   1030 <free@plt>
jmp    13d6 <main+0x146>
lea    0xa27(%rip),%rdi
jmp    15e2 <main+0x352>
lea    0xa42(%rip),%rdi
call   1130 <perror@plt>
mov    $0x1,%edi
call   1180 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [7 x i8] c"server\00"
@.str.2 = [5 x i8] c"port\00"
@.str.3 = [18 x i8] c"Could not connect\00"
@.str.4 = [5 x i8] c"nick\00"
@.str.5 = [9 x i8] c"channels\00"
@.str.6 = [12 x i8] c"bot.log.txt\00"
@.str.7 = [3 x i8] c"a+\00"
@.str.8 = [5 x i8] c"PING\00"
@.str.9 = [32 x i8] c"Got ping. Replying with pong...\00"
@.str.10 = [8 x i8] c"PRIVMSG\00"
@.str.11 = [10 x i8] c"%s/%s: %s\00"
@.str.12 = [11 x i8] c"%s.log.txt\00"
@.str.13 = [5 x i8] c"JOIN\00"
@.str.14 = [14 x i8] c"%s joined %s.\00"
@.str.15 = [5 x i8] c"PART\00"
@.str.16 = [12 x i8] c"%s left %s.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [512 x i8]
%15 = alloca i8*
%16 = alloca [500 x i8]
%17 = alloca [512 x i8]
%18 = alloca i8*
%19 = alloca [500 x i8]
%20 = alloca [512 x i8]
%21 = alloca i8*
%22 = alloca [500 x i8]
store i32 0, i32* %1
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %0
%29 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %0
%32 = call i8* @get_config(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %32, i8** %3
%33 = call i8* @get_config(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %33, i8** %4
%34 = load i8*, i8** %3
%35 = call i32 @inet_addr(i8* %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %38, i32* %39
%40 = load i8*, i8** %4
%41 = call i32 @atoi(i8* %40)
%42 = call i32 @htons(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %4
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %2
%49 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%50 = call i64 @connect(i32 %48, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %31
%53 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %31
%56 = call i8* @get_config(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %56, i8** %6
%57 = call i8* @get_config(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i8* %57, i8** %7
%58 = load i32, i32* %2
%59 = load i8*, i8** %6
%60 = call i32 @set_nick(i32 %58, i8* %59)
%61 = load i32, i32* %2
%62 = load i8*, i8** %6
%63 = call i32 @send_user_packet(i32 %61, i8* %62)
%64 = load i32, i32* %2
%65 = load i8*, i8** %7
%66 = call i32 @join_channel(i32 %64, i8* %65)
%67 = load i8*, i8** %6
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
%71 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %71, i32** %8
br label %72
72: ; preds = %55, %168
%73 = load i32, i32* %2
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%75 = call i32 @read_line(i32 %73, i8* %74)
%76 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%77 = call i8* @get_prefix(i8* %76)
store i8* %77, i8** %10
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%79 = call i8* @get_username(i8* %78)
store i8* %79, i8** %11
%80 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%81 = call i8* @get_command(i8* %80)
store i8* %81, i8** %12
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%83 = call i8* @get_last_argument(i8* %82)
store i8* %83, i8** %13
%84 = load i8*, i8** %12
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %92
87: ; preds = %72
%88 = load i32, i32* %2
%89 = load i8*, i8** %13
%90 = call i32 @send_pong(i32 %88, i8* %89)
%91 = call i32 @log_with_date(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %168
92: ; preds = %72
%93 = load i8*, i8** %12
%94 = call i64 @strcmp(i8* %93, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %117
96: ; preds = %92
%97 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%98 = call i8* @get_argument(i8* %97, i32 1)
store i8* %98, i8** %15
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%100 = load i8*, i8** %15
%101 = load i8*, i8** %11
%102 = load i8*, i8** %13
%103 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %99, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %100, i8* %101, i8* %102)
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%105 = call i32 @log_with_date(i8* %104)
%106 = getelementptr inbounds [500 x i8], [500 x i8]* %16, i64 0, i64 0
%107 = load i8*, i8** %15
%108 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %106, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %107)
%109 = getelementptr inbounds [500 x i8], [500 x i8]* %16, i64 0, i64 0
%110 = load i32*, i32** %8
%111 = call i32 @freopen(i8* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %110)
%112 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%113 = load i32*, i32** %8
%114 = call i32 @log_to_file(i8* %112, i32* %113)
%115 = load i8*, i8** %15
%116 = call i32 @free(i8* %115)
br label %167
117: ; preds = %92
%118 = load i8*, i8** %12
%119 = call i64 @strcmp(i8* %118, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %141
121: ; preds = %117
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%123 = call i8* @get_argument(i8* %122, i32 1)
store i8* %123, i8** %18
%124 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%125 = load i8*, i8** %11
%126 = load i8*, i8** %18
%127 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %124, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0), i8* %125, i8* %126)
%128 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%129 = call i32 @log_with_date(i8* %128)
%130 = getelementptr inbounds [500 x i8], [500 x i8]* %19, i64 0, i64 0
%131 = load i8*, i8** %18
%132 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %130, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %131)
%133 = getelementptr inbounds [500 x i8], [500 x i8]* %19, i64 0, i64 0
%134 = load i32*, i32** %8
%135 = call i32 @freopen(i8* %133, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %134)
%136 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%137 = load i32*, i32** %8
%138 = call i32 @log_to_file(i8* %136, i32* %137)
%139 = load i8*, i8** %18
%140 = call i32 @free(i8* %139)
br label %166
141: ; preds = %117
%142 = load i8*, i8** %12
%143 = call i64 @strcmp(i8* %142, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%144 = icmp eq i64 %143, 0
br i1 %144, label %145, label %165
145: ; preds = %141
%146 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%147 = call i8* @get_argument(i8* %146, i32 1)
store i8* %147, i8** %21
%148 = getelementptr inbounds [512 x i8], [512 x i8]* %20, i64 0, i64 0
%149 = load i8*, i8** %11
%150 = load i8*, i8** %21
%151 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %148, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i8* %149, i8* %150)
%152 = getelementptr inbounds [512 x i8], [512 x i8]* %20, i64 0, i64 0
%153 = call i32 @log_with_date(i8* %152)
%154 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%155 = load i8*, i8** %21
%156 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %154, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %155)
%157 = getelementptr inbounds [500 x i8], [500 x i8]* %22, i64 0, i64 0
%158 = load i32*, i32** %8
%159 = call i32 @freopen(i8* %157, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %158)
%160 = getelementptr inbounds [512 x i8], [512 x i8]* %20, i64 0, i64 0
%161 = load i32*, i32** %8
%162 = call i32 @log_to_file(i8* %160, i32* %161)
%163 = load i8*, i8** %21
%164 = call i32 @free(i8* %163)
br label %165
165: ; preds = %145, %141
br label %166
166: ; preds = %165, %121
br label %167
167: ; preds = %166, %96
br label %168
168: ; preds = %167, %87
%169 = load i8*, i8** %10
%170 = call i32 @free(i8* %169)
%171 = load i8*, i8** %11
%172 = call i32 @free(i8* %171)
%173 = load i8*, i8** %12
%174 = call i32 @free(i8* %173)
%175 = load i8*, i8** %13
%176 = call i32 @free(i8* %175)
br label %72
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [7 x i8] c"server\00"
@.str.2 = [5 x i8] c"port\00"
@.str.3 = [18 x i8] c"Could not connect\00"
@.str.4 = [5 x i8] c"nick\00"
@.str.5 = [9 x i8] c"channels\00"
@.str.6 = [12 x i8] c"bot.log.txt\00"
@.str.7 = [3 x i8] c"a+\00"
@.str.8 = [5 x i8] c"PING\00"
@.str.9 = [32 x i8] c"Got ping. Replying with pong...\00"
@.str.10 = [8 x i8] c"PRIVMSG\00"
@.str.11 = [10 x i8] c"%s/%s: %s\00"
@.str.12 = [11 x i8] c"%s.log.txt\00"
@.str.13 = [5 x i8] c"JOIN\00"
@.str.14 = [14 x i8] c"%s joined %s.\00"
@.str.15 = [5 x i8] c"PART\00"
@.str.16 = [12 x i8] c"%s left %s.\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca [500 x i8]
%5 = alloca [512 x i8]
%6 = alloca [500 x i8]
%7 = alloca [512 x i8]
%8 = alloca [500 x i8]
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = tail call i8* @get_config(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i8* @get_config(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = bitcast %struct.sockaddr_in* %1 to i8*
%20 = tail call i32 @inet_addr(i8* %17)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %22, i32* %23
%24 = tail call i32 @atoi(i8* %18)
%25 = tail call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @free(i8* %17)
%28 = tail call i32 @free(i8* %18)
%29 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%30 = call i64 @connect(i32 %11, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %16
%33 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %16
%36 = call i8* @get_config(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%37 = call i8* @get_config(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @set_nick(i32 %11, i8* %36)
%39 = call i32 @send_user_packet(i32 %11, i8* %36)
%40 = call i32 @join_channel(i32 %11, i8* %37)
%41 = call i32 @free(i8* %36)
%42 = call i32 @free(i8* %37)
%43 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [500 x i8], [500 x i8]* %8, i64 0, i64 0
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%50 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
br label %51
51: ; preds = %95, %35
%52 = call i32 @read_line(i32 %11, i8* %44)
%53 = call i8* @get_prefix(i8* %44)
%54 = call i8* @get_username(i8* %44)
%55 = call i8* @get_command(i8* %44)
%56 = call i8* @get_last_argument(i8* %44)
%57 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = call i32 @send_pong(i32 %11, i8* %56)
%61 = call i32 @log_with_date(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %95
62: ; preds = %51
%63 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %73
65: ; preds = %62
%66 = call i8* @get_argument(i8* %44, i32 1)
%67 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %49, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %66, i8* %54, i8* %56)
%68 = call i32 @log_with_date(i8* %49)
%69 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %50, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %66)
%70 = call i32 @freopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %43)
%71 = call i32 @log_to_file(i8* %49, i32* %43)
%72 = call i32 @free(i8* %66)
br label %95
73: ; preds = %62
%74 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %84
76: ; preds = %73
%77 = call i8* @get_argument(i8* %44, i32 1)
%78 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0), i8* %54, i8* %77)
%79 = call i32 @log_with_date(i8* %47)
%80 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %48, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %77)
%81 = call i32 @freopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %43)
%82 = call i32 @log_to_file(i8* %47, i32* %43)
%83 = call i32 @free(i8* %77)
br label %95
84: ; preds = %73
%85 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %95
87: ; preds = %84
%88 = call i8* @get_argument(i8* %44, i32 1)
%89 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %45, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i8* %54, i8* %88)
%90 = call i32 @log_with_date(i8* %45)
%91 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8* %88)
%92 = call i32 @freopen(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %43)
%93 = call i32 @log_to_file(i8* %45, i32* %43)
%94 = call i32 @free(i8* %88)
br label %95
95: ; preds = %65, %84, %87, %76, %59
%96 = call i32 @free(i8* %53)
%97 = call i32 @free(i8* %54)
%98 = call i32 @free(i8* %55)
%99 = call i32 @free(i8* %56)
br label %51
}