#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 atoi(char *);
int http_download_course(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf(
        "ttsdownload\n\tusage: ttsdownload <course> <start_date> <end_date>\n");
    return -1;
  }
  int start_date, end_date;
  start_date = atoi(argv[2]);
  end_date = atoi(argv[3]);
  if (!start_date || !end_date) {
    printf(
        "ttsdownload\n\tusage: ttsdownload <course> <start_date> <end_date>\n");
    return -1;
  }
  while (start_date <= end_date) {
    char course[20];
    sprintf(course, "%s%04d", argv[1], start_date);
    mkdir(course, 0777);
    int res[2];
    res[0] = http_download_course(course, "am");
    res[1] = http_download_course(course, "pm");
    if ((res[0] == -1) && (res[1] == -1)) {
      remove(course);
    }
    start_date++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <main+0x116>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cc <main+0x6c>
cmpl   $0x0,-0x18(%rbp)
jne    11e4 <main+0x84>
lea    0xe2d(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <main+0x116>
jmp    11e9 <main+0x89>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     126f <main+0x10f>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe37(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
lea    -0x30(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1030 <http_download_course@plt>
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1030 <http_download_course@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1261 <main+0x101>
cmpl   $0xffffffff,-0x34(%rbp)
jne    1261 <main+0x101>
lea    -0x30(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e9 <main+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x4,%edi
jne    121c <main+0xbc>
mov    %rsi,%r15
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%r15),%rdi
call   1070 <atoi@plt>
test   %ebp,%ebp
je     121c <main+0xbc>
mov    %eax,%r13d
test   %eax,%eax
je     121c <main+0xbc>
xor    %eax,%eax
cmp    %r13d,%ebp
jg     122d <main+0xcd>
add    $0x1,%r13d
mov    %rsp,%rbx
lea    0xe50(%rip),%r12
jmp    11c8 <main+0x68>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %ebp,%r13d
je     123c <main+0xdc>
mov    0x8(%r15),%rdx
mov    %rbx,%rdi
lea    0xe2a(%rip),%rsi
mov    %ebp,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    %rbx,%rdi
lea    0xe13(%rip),%rsi
call   1030 <http_download_course@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <http_download_course@plt>
cmp    $0xffffffff,%r14d
jne    11c0 <main+0x60>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1040 <remove@plt>
jmp    11c0 <main+0x60>
lea    0xdea(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    122d <main+0xcd>

LLVM IR (-O0):
@.str = [66 x i8] c"ttsdownload\0A\09usage: ttsdownload <course> <start_date> <end_date>\0A\00"
@.str.1 = [7 x i8] c"%s%04d\00"
@.str.2 = [3 x i8] c"am\00"
@.str.3 = [3 x i8] c"pm\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25, %14
%29 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
30: ; preds = %25
br label %31
31: ; preds = %60, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %63
35: ; preds = %31
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i32, i32* %6
%41 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %39, i32 %40)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%43 = call i32 @mkdir(i8* %42, i32 511)
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%45 = call i32 @http_download_course(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
store i32 %45, i32* %46
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%48 = call i32 @http_download_course(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
store i32 %48, i32* %49
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %60
53: ; preds = %35
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%59 = call i32 @remove(i8* %58)
br label %60
60: ; preds = %57, %53, %35
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %31
63: ; preds = %31
store i32 0, i32* %3
br label %64
64: ; preds = %63, %28, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%s%04d\00"
@.str.2 = [3 x i8] c"am\00"
@.str.3 = [3 x i8] c"pm\00"
@str.4 = [65 x i8] c"ttsdownload\0A\09usage: ttsdownload <course> <start_date> <end_date>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = icmp eq i32 %0, 4
br i1 %4, label %5, label %35
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp ne i32 %8, 0
%13 = icmp ne i32 %11, 0
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %35
15: ; preds = %5
%16 = icmp sgt i32 %8, %11
br i1 %16, label %38, label %17
17: ; preds = %15
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds i8*, i8** %1, i64 1
br label %20
20: ; preds = %17, %32
%21 = phi i32 [ %8, %17 ], [ %33, %32 ]
%22 = load i8*, i8** %19
%23 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %21)
%24 = call i32 @mkdir(i8* %18, i32 511)
%25 = call i32 @http_download_course(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @http_download_course(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32 %25, -1
%28 = icmp eq i32 %26, -1
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @remove(i8* %18)
br label %32
32: ; preds = %30, %20
%33 = add i32 %21, 1
%34 = icmp eq i32 %21, %11
br i1 %34, label %38, label %20
35: ; preds = %5, %2
%36 = phi i8* [ getelementptr inbounds ([65 x i8], [65 x i8]* @str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @str.4, i64 0, i64 0), %5 ]
%37 = tail call i32 @puts(i8* dereferenceable(1) %36)
br label %38
38: ; preds = %32, %35, %15
%39 = phi i32 [ 0, %15 ], [ -1, %35 ], [ 0, %32 ]
ret i32 %39
}