#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*/ pthread_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep_thread_new(int /*<<< orphan*/ *, int *);
int main(int argc, char *argv[]) {
  int number_of_threads = argc - 1;
  int i;
  int *sleeptime = malloc(sizeof(int) * 3);
  pthread_t thread[number_of_threads];
  if (number_of_threads < 1) {
    printf("Bitte mindestens eine Zeit eingeben.\n\tUsage: Thread time1 "
           "[time...]\n");
    exit(-1);
  } else {
    printf("Erstelle %d Threads\n\n", number_of_threads);
  }
  for (i = 0; i < number_of_threads; i++) {
    sleeptime[i] = atoi(argv[i + 1]);
  }
  for (i = 0; i < number_of_threads; i++) {
    sleep_thread_new(&thread[i], &sleeptime[i]);
  }
  for (i = 0; i < number_of_threads; i++) {
    pthread_join(thread[i], NULL);
  }
  free(sleeptime);
  exit(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)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11e6 <main+0x76>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123b <main+0xcb>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fe <main+0x8e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    127f <main+0x10f>
mov    -0x38(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <sleep_thread_new@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1242 <main+0xd2>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12b4 <main+0x144>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <pthread_join@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1286 <main+0x116>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
lea    -0x1(%rbx),%r15d
mov    $0xc,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rsp,%rcx
lea    0xf(,%r15,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,%rsp
cmp    $0x1,%ebx
jg     11d7 <main+0x57>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    %rbx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
lea    0xe1a(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%r13
mov    0x8(%r12,%rbx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14,%rbx,4)
mov    %r13,%rbx
cmp    %r13,%r15
jne    1200 <main+0x80>
cmpl   $0x2,-0x30(%rbp)
mov    -0x38(%rbp),%r13
jl     1274 <main+0xf4>
mov    %r15,%r12
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <sleep_thread_new@plt>
add    $0x4,%rbx
add    $0x4,%r13
add    $0xffffffffffffffff,%r12
jne    1230 <main+0xb0>
cmpl   $0x2,-0x30(%rbp)
mov    -0x38(%rbp),%r12
jl     1274 <main+0xf4>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,4),%edi
xor    %esi,%esi
call   10a0 <pthread_join@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1260 <main+0xe0>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"Bitte mindestens eine Zeit eingeben.\0A\09Usage: Thread time1 [time...]\0A\00"
@.str.1 = [22 x i8] c"Erstelle %d Threads\0A\0A\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 i32*
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %6
%13 = call i32* @malloc(i32 12)
store i32* %13, i32** %8
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i32, i64 %15
store i64 %15, i64* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23
store i32 0, i32* %7
br label %27
27: ; preds = %43, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = load i32*, i32** %8
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
br label %43
43: ; preds = %31
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %27
46: ; preds = %27
store i32 0, i32* %7
br label %47
47: ; preds = %60, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %63
51: ; preds = %47
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %17, i64 %53
%55 = load i32*, i32** %8
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = call i32 @sleep_thread_new(i32* %54, i32* %58)
br label %60
60: ; preds = %51
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %47
63: ; preds = %47
store i32 0, i32* %7
br label %64
64: ; preds = %74, %63
%65 = load i32, i32* %7
%66 = load i32, i32* %6
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %77
68: ; preds = %64
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %17, i64 %70
%72 = load i32, i32* %71
%73 = call i32 @pthread_join(i32 %72, i32* null)
br label %74
74: ; preds = %68
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %64
77: ; preds = %64
%78 = load i32*, i32** %8
%79 = call i32 @free(i32* %78)
%80 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"Erstelle %d Threads\0A\0A\00"
@str = [68 x i8] c"Bitte mindestens eine Zeit eingeben.\0A\09Usage: Thread time1 [time...]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -1
%4 = tail call i32* @malloc(i32 12)
%5 = zext i32 %3 to i64
%6 = alloca i32, i64 %5
%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 ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %3)
br label %15
13: ; preds = %15
%14 = icmp sgt i32 %0, 1
br i1 %14, label %24, label %38
15: ; preds = %11, %15
%16 = phi i64 [ 0, %11 ], [ %17, %15 ]
%17 = add nuw nsw i64 %16, 1
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = getelementptr inbounds i32, i32* %4, i64 %16
store i32 %20, i32* %21
%22 = icmp eq i64 %17, %5
br i1 %22, label %13, label %15
23: ; preds = %24
br i1 %14, label %31, label %38
24: ; preds = %13, %24
%25 = phi i64 [ %29, %24 ], [ 0, %13 ]
%26 = getelementptr inbounds i32, i32* %6, i64 %25
%27 = getelementptr inbounds i32, i32* %4, i64 %25
%28 = call i32 @sleep_thread_new(i32* %26, i32* %27)
%29 = add nuw nsw i64 %25, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %23, label %24
31: ; preds = %23, %31
%32 = phi i64 [ %36, %31 ], [ 0, %23 ]
%33 = getelementptr inbounds i32, i32* %6, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @pthread_join(i32 %34, i32* null)
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %5
br i1 %37, label %38, label %31
38: ; preds = %31, %13, %23
%39 = call i32 @free(i32* %4)
%40 = call i32 @exit(i32 0)
unreachable
}