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

/* Variables and functions */
long download_url_file(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getcwd(char *, int);
char *name_from_url(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
void download_episode(char *url) {
  FILE *fp;
  char cwd[1024];
  char full_path[1024];
  char *name = name_from_url(url);
  getcwd(cwd, sizeof(cwd));
  sprintf(full_path, "%s/casts/%s", cwd, name);
  printf("downloading: %s to %s\n", url, full_path);
  fp = fopen(full_path, "w");
  long status = download_url_file(url, fp);
  if (status != 200)
    printf("Download failed with status: %ld\n", status);
  fclose(fp);
}


x86 assembly (clang, -O0):
<download_episode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <name_from_url@plt>
mov    %rax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rdx
mov    -0x818(%rbp),%rcx
lea    0xe44(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <download_url_file@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0xc8,-0x820(%rbp)
je     122b <download_episode+0xbb>
mov    -0x820(%rbp),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<download_episode>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
call   1070 <name_from_url@plt>
mov    %rax,%rbx
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe5b(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1090 <sprintf@plt>
lea    0xe4f(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rsi
mov    %r12,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <download_url_file@plt>
cmp    $0xc8,%rax
je     1200 <download_episode+0x90>
lea    0xe2f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s/casts/%s\00"
@.str.1 = [23 x i8] c"downloading: %s to %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"Download failed with status: %ld\0A\00"
define void @download_episode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @name_from_url(i8* %8)
store i8* %9, i8** %6
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32 @getcwd(i8* %10, i32 1024)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
%16 = load i8*, i8** %2
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %3
%21 = load i8*, i8** %2
%22 = load i32*, i32** %3
%23 = call i64 @download_url_file(i8* %21, i32* %22)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = icmp ne i64 %24, 200
br i1 %25, label %26, label %29
26: ; preds = %1
%27 = load i64, i64* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %26, %1
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s/casts/%s\00"
@.str.1 = [23 x i8] c"downloading: %s to %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"Download failed with status: %ld\0A\00"
define void @download_episode(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @name_from_url(i8* %0)
%7 = call i32 @getcwd(i8* %4, i32 1024)
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %6)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %5)
%10 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i64 @download_url_file(i8* %0, i32* %10)
%12 = icmp eq i64 %11, 200
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i64 %11)
br label %15
15: ; preds = %13, %1
%16 = call i32 @fclose(i32* %10)
ret void
}