#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 */

/* Variables and functions */
char *encodeFile(char *, char *);
char *encodeInt(int);
char *encodeString(char *);
char *fileSHA(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  printf("Original: Hello world\n");
  printf("Bencoded String: %s\n\n", encodeString("Hello world"));
  printf("Original: 12345\n");
  printf("Bencoded Int: %s\n\n", encodeInt(12345));
  char *torrentFile = malloc(10000);
  torrentFile = encodeFile(argv[1], argv[2]);
  printf("Torrent file of your input file: \n%s\n\n", torrentFile);
  printf("SHA1 of torrent file: \n%s\n", fileSHA(argv[1]));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
call   1040 <encodeString@plt>
mov    %rax,%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3039,%edi
call   1070 <encodeInt@plt>
mov    %rax,%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2710,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <encodeFile@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <fileSHA@plt>
mov    %rax,%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
lea    0xf00(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
call   1050 <encodeString@plt>
lea    0xe7d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3039,%edi
call   1080 <encodeInt@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1070 <encodeFile@plt>
lea    0xe61(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
call   1040 <fileSHA@plt>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Original: Hello world\0A\00"
@.str.1 = [22 x i8] c"Bencoded String: %s\0A\0A\00"
@.str.2 = [12 x i8] c"Hello world\00"
@.str.3 = [17 x i8] c"Original: 12345\0A\00"
@.str.4 = [19 x i8] c"Bencoded Int: %s\0A\0A\00"
@.str.5 = [39 x i8] c"Torrent file of your input file: \0A%s\0A\0A\00"
@.str.6 = [27 x i8] c"SHA1 of torrent file: \0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @encodeString(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%10 = call i8* @encodeInt(i32 12345)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%12 = call i8* @malloc(i32 10000)
store i8* %12, i8** %5
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i8* @encodeFile(i8* %15, i8* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i8* @fileSHA(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"Bencoded String: %s\0A\0A\00"
@.str.2 = [12 x i8] c"Hello world\00"
@.str.4 = [19 x i8] c"Bencoded Int: %s\0A\0A\00"
@.str.5 = [39 x i8] c"Torrent file of your input file: \0A%s\0A\0A\00"
@.str.6 = [27 x i8] c"SHA1 of torrent file: \0A%s\0A\00"
@str = [22 x i8] c"Original: Hello world\00"
@str.7 = [16 x i8] c"Original: 12345\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%4 = tail call i8* @encodeString(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i8* @encodeInt(i32 12345)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i8* @encodeFile(i8* %10, i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %9
%16 = tail call i8* @fileSHA(i8* %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %16)
ret i32 0
}