#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 create_bitfield();
int create_btcache();
int create_files();
int /*<<< orphan*/ do_clear_work();
int /*<<< orphan*/ download_upload_with_peers();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ init_unchoke_peers();
int parse_metafile(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int set_signal_hander();
int main(int argc, char *argv[]) {
  int ret;
  if (argc != 2) {
    printf("usage:%s metafile\n", argv[0]);
    exit(-1);
  }
  ret = set_signal_hander();
  if (ret != 0) {
    printf("%s:%d error\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c",
           28);
    return -1;
  }
  ret = parse_metafile(argv[1]);
  if (ret != 0) {
    printf("%s:%d error\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c",
           32);
    return -1;
  }
  init_unchoke_peers();
  ret = create_files();
  if (ret != 0) {
    printf("%s:%d error\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c",
           39);
    return -1;
  }
  ret = create_bitfield();
  if (ret != 0) {
    printf("%s:%d error\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c",
           43);
    return -1;
  }
  ret = create_btcache();
  if (ret != 0) {
    printf("%s:%d error\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c",
           47);
    return -1;
  }
  download_upload_with_peers();
  do_clear_work();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1060 <set_signal_hander@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1219 <main+0x79>
lea    0xe19(%rip),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x1c,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1323 <main+0x183>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <parse_metafile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1259 <main+0xb9>
lea    0xdd9(%rip),%rdi
lea    0xddf(%rip),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1323 <main+0x183>
mov    $0x0,%al
call   1090 <init_unchoke_peers@plt>
mov    $0x0,%al
call   1070 <create_files@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     129a <main+0xfa>
lea    0xd98(%rip),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x27,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1323 <main+0x183>
mov    $0x0,%al
call   1080 <create_bitfield@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d4 <main+0x134>
lea    0xd5e(%rip),%rdi
lea    0xd64(%rip),%rsi
mov    $0x2b,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1323 <main+0x183>
mov    $0x0,%al
call   1050 <create_btcache@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     130e <main+0x16e>
lea    0xd24(%rip),%rdi
lea    0xd2a(%rip),%rsi
mov    $0x2f,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1323 <main+0x183>
mov    $0x0,%al
call   10b0 <download_upload_with_peers@plt>
mov    $0x0,%al
call   10a0 <do_clear_work@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1279 <main+0xd9>
xor    %eax,%eax
call   1060 <set_signal_hander@plt>
test   %eax,%eax
je     11d0 <main+0x30>
lea    0xe54(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x1c,%edx
jmp    1259 <main+0xb9>
mov    0x8(%rbx),%rdi
call   1030 <parse_metafile@plt>
test   %eax,%eax
je     11f2 <main+0x52>
lea    0xe2f(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x20,%edx
jmp    1259 <main+0xb9>
xor    %eax,%eax
call   1090 <init_unchoke_peers@plt>
xor    %eax,%eax
call   1070 <create_files@plt>
test   %eax,%eax
je     1219 <main+0x79>
lea    0xe08(%rip),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x27,%edx
jmp    1259 <main+0xb9>
xor    %eax,%eax
call   1080 <create_bitfield@plt>
test   %eax,%eax
je     1239 <main+0x99>
lea    0xde8(%rip),%rdi
lea    0xdee(%rip),%rsi
mov    $0x2b,%edx
jmp    1259 <main+0xb9>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <create_btcache@plt>
test   %eax,%eax
je     1269 <main+0xc9>
lea    0xdc6(%rip),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x2f,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
call   10b0 <download_upload_with_peers@plt>
xor    %eax,%eax
call   10a0 <do_clear_work@plt>
jmp    1265 <main+0xc5>
mov    (%rbx),%rsi
lea    0xd7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"usage:%s metafile\0A\00"
@.str.1 = [13 x i8] c"%s:%d error\0A\00"
@.str.2 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 (...) @set_signal_hander()
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 28)
store i32 -1, i32* %3
br label %52
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @parse_metafile(i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 32)
store i32 -1, i32* %3
br label %52
30: ; preds = %21
%31 = call i32 (...) @init_unchoke_peers()
%32 = call i32 (...) @create_files()
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 39)
store i32 -1, i32* %3
br label %52
37: ; preds = %30
%38 = call i32 (...) @create_bitfield()
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 43)
store i32 -1, i32* %3
br label %52
43: ; preds = %37
%44 = call i32 (...) @create_btcache()
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 47)
store i32 -1, i32* %3
br label %52
49: ; preds = %43
%50 = call i32 (...) @download_upload_with_peers()
%51 = call i32 (...) @do_clear_work()
store i32 0, i32* %3
br label %52
52: ; preds = %49, %47, %41, %35, %28, %19
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [19 x i8] c"usage:%s metafile\0A\00"
@.str.1 = [13 x i8] c"%s:%d error\0A\00"
@.str.2 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fryduck/BT_Code/refs/heads/master/main.c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call i32 (...) @set_signal_hander()
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 28)
br label %39
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @parse_metafile(i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 32)
br label %39
20: ; preds = %13
%21 = tail call i32 (...) @init_unchoke_peers()
%22 = tail call i32 (...) @create_files()
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 39)
br label %39
26: ; preds = %20
%27 = tail call i32 (...) @create_bitfield()
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 43)
br label %39
31: ; preds = %26
%32 = tail call i32 (...) @create_btcache()
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 47)
br label %39
36: ; preds = %31
%37 = tail call i32 (...) @download_upload_with_peers()
%38 = tail call i32 (...) @do_clear_work()
br label %39
39: ; preds = %36, %34, %29, %24, %18, %11
%40 = phi i32 [ -1, %11 ], [ -1, %18 ], [ -1, %24 ], [ -1, %29 ], [ -1, %34 ], [ 0, %36 ]
ret i32 %40
}