#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 strlen(char *);
int /*<<< orphan*/ url_encode(char *, char *);
int /*<<< orphan*/ url_hostname(char *, char *);
int /*<<< orphan*/ url_path(char *, char *);
int scrape_build(char request[256], char *info_hash, char *tracker) {
  char *path = (char *)malloc(256);
  char *hostname = (char *)malloc(256);
  char *hash_escape = (char *)malloc(61);
  url_hostname(tracker, hostname);
  url_path(tracker, path);
  url_encode(info_hash, hash_escape);
  sprintf(request,
          "GET %s/scrape.php?info_hash=%s HTTP/1.1\r\nhost: %s\r\n\r\n", path,
          hash_escape, hostname);
  free(path);
  free(hostname);
  free(hash_escape);
  return strlen(request);
}


x86 assembly (clang, -O0):
<scrape_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x3d,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <url_hostname@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <url_path@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <url_encode@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe14(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scrape_build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    $0x3d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <url_hostname@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <url_path@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <url_encode@plt>
lea    0xe2d(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlen@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"GET %s/scrape.php?info_hash=%s HTTP/1.1\0D\0Ahost: %s\0D\0A\0D\0A\00"
define i32 @scrape_build(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = call i64 @malloc(i32 256)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %7
%12 = call i64 @malloc(i32 256)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
%14 = call i64 @malloc(i32 61)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %9
%16 = load i8*, i8** %6
%17 = load i8*, i8** %8
%18 = call i32 @url_hostname(i8* %16, i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i32 @url_path(i8* %19, i8* %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %9
%24 = call i32 @url_encode(i8* %22, i8* %23)
%25 = load i8*, i8** %4
%26 = load i8*, i8** %7
%27 = load i8*, i8** %9
%28 = load i8*, i8** %8
%29 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27, i8* %28)
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %9
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %4
%37 = call i32 @strlen(i8* %36)
ret i32 %37
}

LLVM IR (-O2):
@.str = [54 x i8] c"GET %s/scrape.php?info_hash=%s HTTP/1.1\0D\0Ahost: %s\0D\0A\0D\0A\00"
define i32 @scrape_build(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @malloc(i32 256)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i64 @malloc(i32 256)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @malloc(i32 61)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @url_hostname(i8* %2, i8* %7)
%11 = tail call i32 @url_path(i8* %2, i8* %5)
%12 = tail call i32 @url_encode(i8* %1, i8* %9)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %9, i8* %7)
%14 = tail call i32 @free(i8* %5)
%15 = tail call i32 @free(i8* %7)
%16 = tail call i32 @free(i8* %9)
%17 = tail call i32 @strlen(i8* %0)
ret i32 %17
}