#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*/ download(char *, int, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int ac, char *av[]) {
  int thread_amount = 5;
  char file_name[256] = {0};
  if (ac < 2) {
    printf("usage: qdown URL [thread_amount] [save as]\n");
    printf("example: qdown http://www.baidu.com/img/logo.gif 5 "
           "/home/sunjoy/log.gif\n");
  } else {
    if (ac >= 3)
      sscanf(av[2], "%d", &thread_amount);
    if (ac >= 4) {
      strcpy(file_name, av[3]);
    }
    download(av[1], thread_amount, file_name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11aa <main+0x5a>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
jmp    1201 <main+0xb1>
cmpl   $0x3,-0x8(%rbp)
jl     11cc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xeb2(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmpl   $0x4,-0x8(%rbp)
jl     11ea <main+0x9a>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
lea    -0x120(%rbp),%rdx
call   1070 <download@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
movl   $0x5,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x1,%edi
jg     11de <main+0x9e>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
jmp    1222 <main+0xe2>
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x2,%edi
je     1210 <main+0xd0>
mov    0x10(%rbx),%rdi
lea    0xe0d(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
cmp    $0x4,%ebp
jb     1210 <main+0xd0>
mov    0x18(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x8(%rbx),%rdi
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdx
call   1060 <download@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"usage: qdown URL [thread_amount] [save as]\0A\00"
@.str.1 = [73 x i8] c"example: qdown http://www.baidu.com/img/logo.gif 5 /home/sunjoy/log.gif\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5, i32* %6
%8 = bitcast [256 x i8]* %7 to i8*
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
br label %38
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 3
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %22
22: ; preds = %17, %14
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 4
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %26, i8* %29)
br label %31
31: ; preds = %25, %22
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i32, i32* %6
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 @download(i8* %34, i32 %35, i8* %36)
br label %38
38: ; preds = %31, %11
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@str = [43 x i8] c"usage: qdown URL [thread_amount] [save as]\00"
@str.3 = [72 x i8] c"example: qdown http://www.baidu.com/img/logo.gif 5 /home/sunjoy/log.gif\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = bitcast i32* %3 to i8*
store i32 5, i32* %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.3, i64 0, i64 0))
br label %27
11: ; preds = %2
%12 = icmp eq i32 %0, 2
br i1 %12, label %22, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = icmp ugt i32 %0, 3
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %6, i8* %20)
br label %22
22: ; preds = %11, %18, %13
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* %3
%26 = call i32 @download(i8* %24, i32 %25, i8* %6)
br label %27
27: ; preds = %22, %8
ret i32 0
}