#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*/ buildup(int, int *);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putout(int, int *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int row = 0;
  int k = 0, m = 0, x = 0, S = 0;
  printf("Please enter the row number");
  while (!scanf("%d", &S)) {
    while (getchar() != '\n')
      ;
    printf("please enter again!\n");
  }
  int *n = (int *)malloc((S + 1) * (S / 2) * sizeof(int));
  if (!n) {
    printf("malloc failed!\n");
    return -1;
  }
  buildup(S, n);
  putout(S, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c3 <main+0x63>
jmp    11f1 <main+0x91>
jmp    11c8 <main+0x68>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11e0 <main+0x80>
jmp    11c8 <main+0x68>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    119e <main+0x3e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1241 <main+0xe1>
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <main+0x100>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <buildup@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <putout@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
lea    0xe88(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
test   %eax,%eax
jne    11e2 <main+0x72>
lea    0xe85(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    11c0 <main+0x50>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
test   %eax,%eax
je     11c0 <main+0x50>
mov    0xc(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
shr    %edi
imul   %ecx,%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1221 <main+0xb1>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
mov    %rax,%rsi
call   1070 <buildup@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1030 <putout@plt>
xor    %eax,%eax
jmp    1232 <main+0xc2>
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Please enter the row number\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"please enter again!\0A\00"
@.str.3 = [16 x i8] c"malloc failed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %19, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %21
13: ; preds = %9
br label %14
14: ; preds = %18, %13
%15 = call signext i8 (...) @getchar()
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %9
21: ; preds = %9
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 2
%26 = mul nsw i32 %23, %25
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = icmp ne i32* %32, null
br i1 %33, label %36, label %34
34: ; preds = %21
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
36: ; preds = %21
%37 = load i32, i32* %6
%38 = load i32*, i32** %7
%39 = call i32 @buildup(i32 %37, i32* %38)
%40 = load i32, i32* %6
%41 = load i32*, i32** %7
%42 = call i32 @putout(i32 %40, i32* %41)
store i32 0, i32* %1
br label %43
43: ; preds = %36, %34
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [28 x i8] c"Please enter the row number\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [15 x i8] c"malloc failed!\00"
@str.4 = [20 x i8] c"please enter again!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0, %9
%7 = call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 10
br i1 %8, label %10, label %9
9: ; preds = %6, %10
br label %6
10: ; preds = %6
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %9, label %14
14: ; preds = %10, %0
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
%17 = sdiv i32 %15, 2
%18 = shl i32 %17, 2
%19 = mul i32 %18, %16
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %30
25: ; preds = %14
%26 = load i32, i32* %1
%27 = call i32 @buildup(i32 %26, i32* %21)
%28 = load i32, i32* %1
%29 = call i32 @putout(i32 %28, i32* %21)
br label %30
30: ; preds = %25, %23
%31 = phi i32 [ 0, %25 ], [ -1, %23 ]
ret i32 %31
}