#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 */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, int, int,
                           int, char *, char *);
int strlen(char *);
int /*<<< orphan*/ url_announce(char *, char *);
int /*<<< orphan*/ url_encode(char *, char *);
int /*<<< orphan*/ url_hostname(char *, char *);
void announce_build(char request[300], char *info_hash, char *peer_id,
                    char *tracker, int listenport) {
  char *announce = (char *)malloc(strlen(tracker));
  char *hostname = (char *)malloc(strlen(tracker));
  char *hash_escape = (char *)malloc(61);
  url_hostname(tracker, hostname);
  url_announce(tracker, announce);
  url_encode(info_hash, hash_escape);
  sprintf(request,
          "GET "
          "%s?info_hash=%s&peer_id=%s&port=%d&ip=127.0.0.1&downloaded=%d&left=%"
          "d&event=%s&numwant=50 HTTP/1.1\r\nhost: %s\r\n\r\n",
          announce, hash_escape, peer_id, listenport, 12008, 12379, "started",
          hostname);
  free(hash_escape);
  free(announce);
  free(hostname);
  return;
}


x86 assembly (clang, -O0):
<announce_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x3d,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <url_hostname@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <url_announce@plt>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <url_encode@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    -0x38(%rbp),%rax
lea    0xdf8(%rip),%rsi
lea    0xe66(%rip),%r10
movl   $0x2ee8,(%rsp)
movl   $0x305b,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1080 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<announce_build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0xc(%rsp)
mov    %rcx,%r14
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rcx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    $0x3d,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <url_hostname@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <url_announce@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <url_encode@plt>
lea    0xe8b(%rip),%rax
lea    0xe0f(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    0x10(%rsp),%r8
mov    0xc(%rsp),%r9d
push   %rbp
push   %rax
push   $0x305b
push   $0x2ee8
call   1080 <sprintf@plt>
add    $0x20,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [117 x i8] c"GET %s?info_hash=%s&peer_id=%s&port=%d&ip=127.0.0.1&downloaded=%d&left=%d&event=%s&numwant=50 HTTP/1.1\0D\0Ahost: %s\0D\0A\0D\0A\00"
@.str.1 = [8 x i8] c"started\00"
define void @announce_build(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%14 = load i8*, i8** %9
%15 = call i32 @strlen(i8* %14)
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %11
%18 = load i8*, i8** %9
%19 = call i32 @strlen(i8* %18)
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %12
%22 = call i64 @malloc(i32 61)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %13
%24 = load i8*, i8** %9
%25 = load i8*, i8** %12
%26 = call i32 @url_hostname(i8* %24, i8* %25)
%27 = load i8*, i8** %9
%28 = load i8*, i8** %11
%29 = call i32 @url_announce(i8* %27, i8* %28)
%30 = load i8*, i8** %7
%31 = load i8*, i8** %13
%32 = call i32 @url_encode(i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = load i8*, i8** %11
%35 = load i8*, i8** %13
%36 = load i8*, i8** %8
%37 = load i32, i32* %10
%38 = load i8*, i8** %12
%39 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([117 x i8], [117 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35, i8* %36, i32 %37, i32 12008, i32 12379, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %13
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %11
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %12
%45 = call i32 @free(i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [117 x i8] c"GET %s?info_hash=%s&peer_id=%s&port=%d&ip=127.0.0.1&downloaded=%d&left=%d&event=%s&numwant=50 HTTP/1.1\0D\0Ahost: %s\0D\0A\0D\0A\00"
@.str.1 = [8 x i8] c"started\00"
define void @announce_build(i8* nocapture writeonly %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i32 @strlen(i8* %3)
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strlen(i8* %3)
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i64 @malloc(i32 61)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @url_hostname(i8* %3, i8* %11)
%15 = tail call i32 @url_announce(i8* %3, i8* %8)
%16 = tail call i32 @url_encode(i8* %1, i8* %13)
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([117 x i8], [117 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %13, i8* %2, i32 %4, i32 12008, i32 12379, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%18 = tail call i32 @free(i8* %13)
%19 = tail call i32 @free(i8* %8)
%20 = tail call i32 @free(i8* %11)
ret void
}