#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 /*<<< orphan*/ free(char **);
char *get_temp_file(char const *, char const *, int);
char **malloc_or_die(int);
int /*<<< orphan*/ tracecmd_attach_cpu_data_fd(int, int, char **);
void put_together_file(int cpus, int ofd, const char *node, const char *port) {
  char **temp_files;
  int cpu;
  temp_files = malloc_or_die(sizeof(*temp_files) * cpus);
  for (cpu = 0; cpu < cpus; cpu++)
    temp_files[cpu] = get_temp_file(node, port, cpu);
  tracecmd_attach_cpu_data_fd(ofd, cpus, temp_files);
  free(temp_files);
}


x86 assembly (clang, -O0):
<put_together_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc_or_die@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a9 <put_together_file+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <get_temp_file@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1170 <put_together_file+0x30>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <tracecmd_attach_cpu_data_fd@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_together_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,0x4(%rsp)
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1050 <malloc_or_die@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jle    119b <put_together_file+0x5b>
mov    %r15d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <get_temp_file@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <put_together_file+0x40>
mov    0x4(%rsp),%edi
mov    %r15d,%esi
mov    %rbp,%rdx
call   1040 <tracecmd_attach_cpu_data_fd@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @put_together_file(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call i8** @malloc_or_die(i32 %14)
store i8** %15, i8*** %9
store i32 0, i32* %10
br label %16
16: ; preds = %29, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = load i32, i32* %10
%24 = call i8* @get_temp_file(i8* %21, i8* %22, i32 %23)
%25 = load i8**, i8*** %9
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
store i8* %24, i8** %28
br label %29
29: ; preds = %20
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %16
32: ; preds = %16
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = load i8**, i8*** %9
%36 = call i32 @tracecmd_attach_cpu_data_fd(i32 %33, i32 %34, i8** %35)
%37 = load i8**, i8*** %9
%38 = call i32 @free(i8** %37)
ret void
}

LLVM IR (-O2):
define void @put_together_file(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = shl i32 %0, 3
%6 = tail call i8** @malloc_or_die(i32 %5)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = trunc i64 %11 to i32
%13 = tail call i8* @get_temp_file(i8* %2, i8* %3, i32 %12)
%14 = getelementptr inbounds i8*, i8** %6, i64 %11
store i8* %13, i8** %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %4
%18 = tail call i32 @tracecmd_attach_cpu_data_fd(i32 %1, i32 %0, i8** %6)
%19 = tail call i32 @free(i8** %6)
ret void
}