#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 */
struct task_set {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ evt_activation(unsigned int, int, unsigned long long);
int /*<<< orphan*/ evt_creation(unsigned int, char const *, int,
                                unsigned long long);
int /*<<< orphan*/ taskset_add_task(struct task_set *, unsigned int, int,
                                    void *);
struct task_set *taskset_init();
scalar_t__ taskset_nth_task(struct task_set *, int /*<<< orphan*/,
                            unsigned int *, int *);
int create(unsigned long long int time, unsigned int pid, const char *name,
           int cpu) {
  unsigned int i = 0, found = 0, existing = 0;
  static struct task_set *ts;
  if (ts == NULL) {
    ts = taskset_init();
  }
  while (!found) {
    unsigned int task_pid;
    int task_cpu;
    if (taskset_nth_task(ts, i++, &task_pid, &task_cpu)) {
      if (pid == task_pid) {
        existing = 1;
        if (cpu == task_cpu) {
          found = 1;
        }
      }
    } else {
      found = 2;
    }
  }
  if (found == 2) {
    taskset_add_task(ts, pid, cpu, (void *)1);
    evt_creation(pid, name, cpu, time);
    if (!existing)
      evt_activation(pid, cpu, time);
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,0x2ecd(%rip)
jne    1197 <create+0x47>
mov    $0x0,%al
call   1060 <taskset_init@plt>
mov    %rax,0x2eb9(%rip)
jmp    119c <create+0x4c>
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b2 <create+0x62>
jmp    1217 <create+0xc7>
mov    0x2e97(%rip),%rdi
mov    -0x28(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <taskset_nth_task@plt>
cmp    $0x0,%rax
je     120b <create+0xbb>
mov    -0x14(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    1206 <create+0xb6>
movl   $0x1,-0x30(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    1201 <create+0xb1>
movl   $0x1,-0x2c(%rbp)
jmp    1206 <create+0xb6>
jmp    1212 <create+0xc2>
movl   $0x2,-0x2c(%rbp)
jmp    119c <create+0x4c>
cmpl   $0x2,-0x2c(%rbp)
jne    1270 <create+0x120>
mov    0x2e28(%rip),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    $0x1,%ecx
call   1050 <taskset_add_task@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1070 <evt_creation@plt>
cmpl   $0x0,-0x30(%rbp)
jne    1264 <create+0x114>
mov    -0x14(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <evt_activation@plt>
movl   $0x0,-0x4(%rbp)
jmp    1277 <create+0x127>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,0x8(%rsp)
mov    %esi,%r13d
mov    %rdi,0x10(%rsp)
cmpq   $0x0,0x2eda(%rip)
jne    1186 <create+0x36>
xor    %eax,%eax
call   1060 <taskset_init@plt>
mov    %rax,0x2eca(%rip)
xor    %ebx,%ebx
lea    0x4(%rsp),%rbp
mov    %rsp,%r15
xor    %eax,%eax
xor    %r14d,%r14d
test   %eax,%eax
je     11a7 <create+0x57>
jmp    11ec <create+0x9c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
test   %eax,%eax
jne    11ec <create+0x9c>
mov    0x2ea2(%rip),%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1030 <taskset_nth_task@plt>
test   %rax,%rax
je     11e0 <create+0x90>
xor    %eax,%eax
cmp    %r13d,0x4(%rsp)
jne    11a0 <create+0x50>
xor    %eax,%eax
cmp    %r12d,(%rsp)
sete   %al
mov    $0x1,%r14d
jmp    11a0 <create+0x50>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%eax
add    $0x1,%ebx
test   %eax,%eax
je     11a7 <create+0x57>
cmp    $0x2,%eax
jne    1237 <create+0xe7>
mov    0x2e58(%rip),%rdi
mov    $0x1,%ecx
mov    %r13d,%esi
mov    %r12d,%edx
call   1050 <taskset_add_task@plt>
mov    %r13d,%edi
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
mov    0x10(%rsp),%rbp
mov    %rbp,%rcx
call   1070 <evt_creation@plt>
xor    %ebx,%ebx
test   %r14d,%r14d
jne    123c <create+0xec>
mov    %r13d,%edi
mov    %r12d,%esi
mov    %rbp,%rdx
call   1040 <evt_activation@plt>
jmp    123c <create+0xec>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.task_set = type { i32 }
@create.ts = internal global %struct.task_set* null
define i32 @create(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i64 %0, i64* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load %struct.task_set*, %struct.task_set** @create.ts
%16 = icmp eq %struct.task_set* %15, null
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call %struct.task_set* (...) @taskset_init()
store %struct.task_set* %18, %struct.task_set** @create.ts
br label %19
19: ; preds = %17, %4
br label %20
20: ; preds = %42, %19
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %43
24: ; preds = %20
%25 = load %struct.task_set*, %struct.task_set** @create.ts
%26 = load i32, i32* %10
%27 = add i32 %26, 1
store i32 %27, i32* %10
%28 = call i64 @taskset_nth_task(%struct.task_set* %25, i32 %26, i32* %13, i32* %14)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %24
%31 = load i32, i32* %7
%32 = load i32, i32* %13
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %30
store i32 1, i32* %12
%35 = load i32, i32* %9
%36 = load i32, i32* %14
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 1, i32* %11
br label %39
39: ; preds = %38, %34
br label %40
40: ; preds = %39, %30
br label %42
41: ; preds = %24
store i32 2, i32* %11
br label %42
42: ; preds = %41, %40
br label %20
43: ; preds = %20
%44 = load i32, i32* %11
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %64
46: ; preds = %43
%47 = load %struct.task_set*, %struct.task_set** @create.ts
%48 = load i32, i32* %7
%49 = load i32, i32* %9
%50 = call i32 @taskset_add_task(%struct.task_set* %47, i32 %48, i32 %49, i8* inttoptr (i64 1 to i8*))
%51 = load i32, i32* %7
%52 = load i8*, i8** %8
%53 = load i32, i32* %9
%54 = load i64, i64* %6
%55 = call i32 @evt_creation(i32 %51, i8* %52, i32 %53, i64 %54)
%56 = load i32, i32* %12
%57 = icmp ne i32 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %46
%59 = load i32, i32* %7
%60 = load i32, i32* %9
%61 = load i64, i64* %6
%62 = call i32 @evt_activation(i32 %59, i32 %60, i64 %61)
br label %63
63: ; preds = %58, %46
store i32 0, i32* %5
br label %65
64: ; preds = %43
store i32 1, i32* %5
br label %65
65: ; preds = %64, %63
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
%struct.task_set = type { i32 }
@create.ts = internal unnamed_addr global %struct.task_set* null
define i32 @create(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = load %struct.task_set*, %struct.task_set** @create.ts
%8 = icmp eq %struct.task_set* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call %struct.task_set* (...) @taskset_init()
store %struct.task_set* %10, %struct.task_set** @create.ts
br label %11
11: ; preds = %9, %4
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
br label %14
14: ; preds = %30, %11
%15 = phi i32 [ 0, %11 ], [ %20, %30 ]
%16 = phi i32 [ 0, %11 ], [ %31, %30 ]
%17 = phi i32 [ 0, %11 ], [ %32, %30 ]
switch i32 %16, label %40 [
i32 0, label %18
i32 2, label %33
]
18: ; preds = %14
%19 = load %struct.task_set*, %struct.task_set** @create.ts
%20 = add i32 %15, 1
%21 = call i64 @taskset_nth_task(%struct.task_set* %19, i32 %15, i32* %5, i32* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, %3
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %26, %18, %23
%31 = phi i32 [ 0, %23 ], [ %29, %26 ], [ 2, %18 ]
%32 = phi i32 [ %17, %23 ], [ 1, %26 ], [ %17, %18 ]
br label %14
33: ; preds = %14
%34 = load %struct.task_set*, %struct.task_set** @create.ts
%35 = call i32 @taskset_add_task(%struct.task_set* %34, i32 %1, i32 %3, i8* inttoptr (i64 1 to i8*))
%36 = call i32 @evt_creation(i32 %1, i8* %2, i32 %3, i64 %0)
%37 = icmp eq i32 %17, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @evt_activation(i32 %1, i32 %3, i64 %0)
br label %40
40: ; preds = %14, %33, %38
%41 = phi i32 [ 0, %38 ], [ 0, %33 ], [ 1, %14 ]
ret i32 %41
}