#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 jtnode_t {
  int dummy;
};

/* Variables and functions */
struct jtnode_t *jtree_create_node(int, int, int, short);
struct jtnode_t **malloc(short);
scalar_t__ scanf(char *, int *, int *, int *);
struct jtnode_t **jtree_read_jobs(short n) {
  short i;
  struct jtnode_t **jobs = malloc(n * sizeof *jobs);
  int r, d, p;
  for (i = 0; i < n; i++) {
    if (scanf("%d %d %d", &r, &d, &p))
      jobs[i] = jtree_create_node(r, d, p, i);
  }
  return jobs;
}


x86 assembly (clang, -O0):
<jtree_read_jobs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movswq -0x2(%rbp),%rax
shl    $0x3,%rax
movswl %ax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movw   $0x0,-0x4(%rbp)
movswl -0x4(%rbp),%eax
movswl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jge    11c4 <jtree_read_jobs+0x94>
lea    0xe8f(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1050 <scanf@plt>
cmp    $0x0,%rax
je     11ae <jtree_read_jobs+0x7e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
movswl -0x4(%rbp),%ecx
call   1040 <jtree_create_node@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movswq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11b3 <jtree_read_jobs+0x83>
mov    -0x4(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x4(%rbp)
jmp    115a <jtree_read_jobs+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jtree_read_jobs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %edi,%eax
shl    $0x3,%eax
movswl %ax,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %bp,%bp
jle    11ae <jtree_read_jobs+0x7e>
movzwl %bp,%ebp
xor    %r14d,%r14d
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    1179 <jtree_read_jobs+0x49>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%rbp
je     11ae <jtree_read_jobs+0x7e>
lea    0xe80(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1050 <scanf@plt>
test   %rax,%rax
je     1170 <jtree_read_jobs+0x40>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
movswl %r14w,%ecx
call   1040 <jtree_create_node@plt>
mov    %rax,(%rbx,%r14,8)
jmp    1170 <jtree_read_jobs+0x40>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.jtnode_t = type { i32 }
@.str = [9 x i8] c"%d %d %d\00"
define %struct.jtnode_t** @jtree_read_jobs(i16 signext %0) {
%2 = alloca i16
%3 = alloca i16
%4 = alloca %struct.jtnode_t**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i16 %0, i16* %2
%8 = load i16, i16* %2
%9 = sext i16 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i16
%12 = call %struct.jtnode_t** @malloc(i16 signext %11)
store %struct.jtnode_t** %12, %struct.jtnode_t*** %4
store i16 0, i16* %3
br label %13
13: ; preds = %33, %1
%14 = load i16, i16* %3
%15 = sext i16 %14 to i32
%16 = load i16, i16* %2
%17 = sext i16 %16 to i32
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %36
19: ; preds = %13
%20 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = load i16, i16* %3
%27 = call %struct.jtnode_t* @jtree_create_node(i32 %23, i32 %24, i32 %25, i16 signext %26)
%28 = load %struct.jtnode_t**, %struct.jtnode_t*** %4
%29 = load i16, i16* %3
%30 = sext i16 %29 to i64
%31 = getelementptr inbounds %struct.jtnode_t*, %struct.jtnode_t** %28, i64 %30
store %struct.jtnode_t* %27, %struct.jtnode_t** %31
br label %32
32: ; preds = %22, %19
br label %33
33: ; preds = %32
%34 = load i16, i16* %3
%35 = add i16 %34, 1
store i16 %35, i16* %3
br label %13
36: ; preds = %13
%37 = load %struct.jtnode_t**, %struct.jtnode_t*** %4
ret %struct.jtnode_t** %37
}

LLVM IR (-O2):
%struct.jtnode_t = type { i32 }
@.str = [9 x i8] c"%d %d %d\00"
define noalias %struct.jtnode_t** @jtree_read_jobs(i16 signext %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = shl i16 %0, 3
%6 = tail call %struct.jtnode_t** @malloc(i16 signext %5)
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = icmp sgt i16 %0, 0
br i1 %10, label %11, label %27
11: ; preds = %1
%12 = zext i16 %0 to i64
br label %13
13: ; preds = %11, %24
%14 = phi i64 [ 0, %11 ], [ %25, %24 ]
%15 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = trunc i64 %14 to i16
%22 = call %struct.jtnode_t* @jtree_create_node(i32 %18, i32 %19, i32 %20, i16 signext %21)
%23 = getelementptr inbounds %struct.jtnode_t*, %struct.jtnode_t** %6, i64 %14
store %struct.jtnode_t* %22, %struct.jtnode_t** %23
br label %24
24: ; preds = %13, %17
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %13
27: ; preds = %24, %1
ret %struct.jtnode_t** %6
}