#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 socklen_t;
typedef int /*<<< orphan*/ remote_addr;
typedef int /*<<< orphan*/ RSA;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ERR_free_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ NID_sha1;
int /*<<< orphan*/ OpenSSL_add_all_ciphers();
int /*<<< orphan*/ *PEM_read_RSAPrivateKey(int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int RSA_sign(int /*<<< orphan*/, unsigned char *, unsigned int, unsigned char *,
             unsigned int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, unsigned int, int /*<<< orphan*/, struct sockaddr *,
           int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned int strlen(char *);
int main(int argc, char **argv) {
  int sockfd;
  int retval;
  struct sockaddr_in remote_addr;
  socklen_t addr_len;
  FILE *file;
  RSA *private_key;
  unsigned int message_len, sig_len;
  char buff[256] = "Laboratorium PUS.";
  if (argc != 3) {
    fprintf(stderr, "Invocation: %s <IPv4 ADDRESS> <PORT>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  file = fopen("private.key", "r");
  if (file == NULL) {
    perror("fopen()");
    exit(EXIT_FAILURE);
  }
  sockfd = socket(PF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  memset(&remote_addr, 0, sizeof(remote_addr));
  remote_addr.sin_family = AF_INET;
  retval = inet_pton(AF_INET, argv[1], &remote_addr.sin_addr);
  if (retval == 0) {
    fprintf(stderr, "inet_pton(): invalid network address!\n");
    exit(EXIT_FAILURE);
  } else if (retval == -1) {
    perror("inet_pton()");
    exit(EXIT_FAILURE);
  }
  remote_addr.sin_port = htons(atoi(argv[2]));
  addr_len = sizeof(remote_addr);
  fprintf(stdout, "Signing message...\n");
  ERR_load_crypto_strings();
  OpenSSL_add_all_ciphers();
  private_key = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL);
  if (!private_key) {
    ERR_print_errors_fp(stderr);
    exit(EXIT_FAILURE);
  }
  fclose(file);
  message_len = strlen(buff);
  retval = RSA_sign(NID_sha1, (unsigned char *)buff, message_len,
                    (unsigned char *)buff + message_len, &sig_len, private_key);
  if (retval == 0) {
    ERR_print_errors_fp(stderr);
    exit(EXIT_FAILURE);
  }
  RSA_free(private_key);
  EVP_cleanup();
  ERR_free_strings();
  fprintf(stdout, "Signature size: %u bytes.\n", sig_len);
  fprintf(stdout, "Sending signed message to %s.\n", argv[1]);
  retval = sendto(sockfd, buff, message_len + sig_len, 0,
                  (struct sockaddr *)&remote_addr, addr_len);
  if (retval == -1) {
    perror("sendto()");
    exit(EXIT_FAILURE);
  }
  close(sockfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x150(%rbp),%rdi
lea    0xd79(%rip),%rsi
mov    $0x100,%edx
call   10c0 <memcpy@plt>
cmpl   $0x3,-0x8(%rbp)
je     12c7 <main+0x67>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
lea    0xe58(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1303 <main+0xa3>
lea    0xe44(%rip),%rdi
call   1120 <perror@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1343 <main+0xe3>
lea    0xe0c(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
call   10e0 <inet_pton@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    13af <main+0x14f>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    13d3 <main+0x173>
lea    0xdac(%rip),%rdi
call   1120 <perror@plt>
mov    0x2bec(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
jmp    13d8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   1150 <ERR_load_crypto_strings@plt>
mov    $0x0,%al
call   1100 <OpenSSL_add_all_ciphers@plt>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   10f0 <PEM_read_RSAPrivateKey@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1459 <main+0x1f9>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   1170 <ERR_print_errors_fp@plt>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x150(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    -0x150(%rbp),%rcx
mov    -0x44(%rbp),%eax
add    %rax,%rcx
mov    -0x40(%rbp),%r9
lea    -0x48(%rbp),%r8
call   1130 <RSA_sign@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    14c7 <main+0x267>
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
call   1170 <ERR_print_errors_fp@plt>
mov    0x2af8(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x40(%rbp),%rdi
call   1060 <RSA_free@plt>
mov    $0x0,%al
call   10b0 <EVP_cleanup@plt>
mov    $0x0,%al
call   10d0 <ERR_free_strings@plt>
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
lea    0xc9b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ab1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc97(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    -0x44(%rbp),%edx
add    -0x48(%rbp),%edx
lea    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    155d <main+0x2fd>
lea    0xc7c(%rip),%rdi
call   1120 <perror@plt>
mov    0x2a62(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    0x2a3c(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xd83(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x100,%edx
call   10c0 <memcpy@plt>
cmp    $0x3,%ebp
jne    12b5 <main+0x55>
lea    0xe8e(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
jne    12d4 <main+0x74>
lea    0xe84(%rip),%rdi
jmp    1356 <main+0xf6>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    135b <main+0xfb>
mov    %rax,%rbp
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
cmp    $0xffffffff,%eax
jne    12fe <main+0x9e>
lea    0xe40(%rip),%rdi
jmp    1356 <main+0xf6>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdx
call   10e0 <inet_pton@plt>
cmp    $0xffffffff,%eax
je     134f <main+0xef>
test   %eax,%eax
jne    1369 <main+0x109>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    135b <main+0xfb>
lea    0xe16(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    0x10(%rbx),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2c2c(%rip),%r13
mov    0x0(%r13),%edi
lea    0xde9(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   1150 <ERR_load_crypto_strings@plt>
xor    %eax,%eax
call   1100 <OpenSSL_add_all_ciphers@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10f0 <PEM_read_RSAPrivateKey@plt>
test   %rax,%rax
je     13f7 <main+0x197>
mov    %rax,%r15
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%eax
lea    0x20(%rsp,%rax,1),%rcx
lea    0xc(%rsp),%r8
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15,%r9
call   1130 <RSA_sign@plt>
test   %eax,%eax
jne    140a <main+0x1aa>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   1170 <ERR_print_errors_fp@plt>
jmp    135b <main+0xfb>
mov    %r15,%rdi
call   1060 <RSA_free@plt>
xor    %eax,%eax
call   10b0 <EVP_cleanup@plt>
xor    %eax,%eax
call   10d0 <ERR_free_strings@plt>
mov    0x0(%r13),%edi
mov    0xc(%rsp),%edx
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x0(%r13),%edi
mov    0x8(%rbx),%rdx
lea    0xd62(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
add    0xc(%rsp),%ebp
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%r8
mov    %r14d,%edi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    147d <main+0x21d>
lea    0xd4e(%rip),%rdi
jmp    1356 <main+0xf6>
mov    %r14d,%edi
call   1090 <close@plt>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buff = [256 x i8] c"Laboratorium PUS.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [38 x i8] c"Invocation: %s <IPv4 ADDRESS> <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"private.key\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"fopen()\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@.str.5 = [39 x i8] c"inet_pton(): invalid network address!\0A\00"
@.str.6 = [12 x i8] c"inet_pton()\00"
@stdout = global i32 0
@.str.7 = [20 x i8] c"Signing message...\0A\00"
@NID_sha1 = global i32 0
@.str.8 = [27 x i8] c"Signature size: %u bytes.\0A\00"
@.str.9 = [31 x i8] c"Sending signed message to %s.\0A\00"
@.str.10 = [9 x i8] c"sendto()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [256 x i8]* %14 to i8*
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %26
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %10
%28 = load i32*, i32** %10
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = load i32, i32* @PF_INET
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %34
%45 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %46, i32* %47
%48 = load i32, i32* @AF_INET
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%53 = call i32 @inet_pton(i32 %48, i8* %51, i32* %52)
store i32 %53, i32* %7
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %44
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %44
%62 = load i32, i32* %7
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %61
br label %69
69: ; preds = %68
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 2
%72 = load i8*, i8** %71
%73 = call i32 @atoi(i8* %72)
%74 = call i32 @htons(i32 %73)
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %74, i32* %75
store i32 12, i32* %9
%76 = load i32, i32* @stdout
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%78 = call i32 (...) @ERR_load_crypto_strings()
%79 = call i32 (...) @OpenSSL_add_all_ciphers()
%80 = load i32*, i32** %10
%81 = call i32* @PEM_read_RSAPrivateKey(i32* %80, i32* null, i32* null, i32* null)
store i32* %81, i32** %11
%82 = load i32*, i32** %11
%83 = icmp ne i32* %82, null
br i1 %83, label %89, label %84
84: ; preds = %69
%85 = load i32, i32* @stderr
%86 = call i32 @ERR_print_errors_fp(i32 %85)
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %69
%90 = load i32*, i32** %10
%91 = call i32 @fclose(i32* %90)
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
store i32 %93, i32* %12
%94 = load i32, i32* @NID_sha1
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%96 = load i32, i32* %12
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%98 = load i32, i32* %12
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
%101 = load i32*, i32** %11
%102 = call i32 @RSA_sign(i32 %94, i8* %95, i32 %96, i8* %100, i32* %13, i32* %101)
store i32 %102, i32* %7
%103 = load i32, i32* %7
%104 = icmp eq i32 %103, 0
br i1 %104, label %105, label %110
105: ; preds = %89
%106 = load i32, i32* @stderr
%107 = call i32 @ERR_print_errors_fp(i32 %106)
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %89
%111 = load i32*, i32** %11
%112 = call i32 @RSA_free(i32* %111)
%113 = call i32 (...) @EVP_cleanup()
%114 = call i32 (...) @ERR_free_strings()
%115 = load i32, i32* @stdout
%116 = load i32, i32* %13
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %116)
%118 = load i32, i32* @stdout
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 1
%121 = load i8*, i8** %120
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %121)
%123 = load i32, i32* %6
%124 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%125 = load i32, i32* %12
%126 = load i32, i32* %13
%127 = add i32 %125, %126
%128 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%129 = load i32, i32* %9
%130 = call i32 @sendto(i32 %123, i8* %124, i32 %127, i32 0, %struct.sockaddr* %128, i32 %129)
store i32 %130, i32* %7
%131 = load i32, i32* %7
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %137
133: ; preds = %110
%134 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%135 = load i32, i32* @EXIT_FAILURE
%136 = call i32 @exit(i32 %135)
unreachable
137: ; preds = %110
%138 = load i32, i32* %6
%139 = call i32 @close(i32 %138)
%140 = load i32, i32* @EXIT_SUCCESS
%141 = call i32 @exit(i32 %140)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buff = [256 x i8] c"Laboratorium PUS.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [38 x i8] c"Invocation: %s <IPv4 ADDRESS> <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"private.key\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"fopen()\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@.str.5 = [39 x i8] c"inet_pton(): invalid network address!\0A\00"
@.str.6 = [12 x i8] c"inet_pton()\00"
@stdout = global i32 0
@.str.7 = [20 x i8] c"Signing message...\0A\00"
@NID_sha1 = global i32 0
@.str.8 = [27 x i8] c"Signature size: %u bytes.\0A\00"
@.str.9 = [31 x i8] c"Sending signed message to %s.\0A\00"
@.str.10 = [9 x i8] c"sendto()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = tail call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
%33 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %34, i32* %35
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%39 = call i32 @inet_pton(i32 %34, i8* %37, i32* %38)
switch i32 %39, label %49 [
i32 0, label %40
i32 -1, label %45
]
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %32
%46 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %32
%50 = getelementptr inbounds i8*, i8** %1, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%57 = call i32 (...) @ERR_load_crypto_strings()
%58 = call i32 (...) @OpenSSL_add_all_ciphers()
%59 = call i32* @PEM_read_RSAPrivateKey(i32* %17, i32* null, i32* null, i32* null)
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %66
61: ; preds = %49
%62 = load i32, i32* @stderr
%63 = call i32 @ERR_print_errors_fp(i32 %62)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %49
%67 = call i32 @fclose(i32* %17)
%68 = call i32 @strlen(i8* %8)
%69 = load i32, i32* @NID_sha1
%70 = zext i32 %68 to i64
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %70
%72 = call i32 @RSA_sign(i32 %69, i8* %8, i32 %68, i8* %71, i32* %4, i32* %59)
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %66
%75 = load i32, i32* @stderr
%76 = call i32 @ERR_print_errors_fp(i32 %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %66
%80 = call i32 @RSA_free(i32* %59)
%81 = call i32 (...) @EVP_cleanup()
%82 = call i32 (...) @ERR_free_strings()
%83 = load i32, i32* @stdout
%84 = load i32, i32* %4
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i32 %84)
%86 = load i32, i32* @stdout
%87 = load i8*, i8** %36
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %87)
%89 = load i32, i32* %4
%90 = add i32 %89, %68
%91 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%92 = call i32 @sendto(i32 %26, i8* %8, i32 %90, i32 0, %struct.sockaddr* %91, i32 12)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %79
%95 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %79
%99 = call i32 @close(i32 %26)
%100 = load i32, i32* @EXIT_SUCCESS
%101 = call i32 @exit(i32 %100)
unreachable
}