#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *);
scalar_t__ snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *,
                    char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ system(char *);
int main(int argc, char const *argv[]) {
  if (argc > 1) {
    for (int i = 1; i < argc; i++) {
      char *command =
          (char *)malloc(snprintf(NULL, 0, "megadl '%s' &", argv[i]) + 1);
      sprintf(command, "megadl '%s' &", argv[i]);
      system(command);
    }
  } else {
    printf("Usage: ./megas link1 link2 link3 link4 linkn\n");
  }
  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   $0x1,-0x8(%rbp)
jle    11e9 <main+0x99>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e4 <main+0x94>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe64(%rip),%rdx
call   1050 <snprintf@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe38(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <system@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <main+0x27>
jmp    11f5 <main+0xa5>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     11ae <main+0x5e>
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xe90(%rip),%r14
mov    (%r15,%rbx,8),%rcx
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <snprintf@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    (%r15,%rbx,8),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    %r13,%rdi
call   1040 <system@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <main+0x20>
jmp    11ba <main+0x6a>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"megadl '%s' &\00"
@.str.1 = [46 x i8] c"Usage: ./megas link1 link2 link3 link4 linkn\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %38
10: ; preds = %2
store i32 1, i32* %6
br label %11
11: ; preds = %34, %10
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = add nsw i64 %21, 1
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @system(i8* %32)
br label %34
34: ; preds = %15
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %11
37: ; preds = %11
br label %40
38: ; preds = %2
%39 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"megadl '%s' &\00"
@str = [45 x i8] c"Usage: ./megas link1 link2 link3 link4 linkn\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %17, %6 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = add nsw i64 %10, 1
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = load i8*, i8** %8
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @system(i8* %13)
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %21, label %6
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %6, %19
ret i32 0
}