#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*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quick_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n, *a, k = -1;
  printf("Введите количество элементов в массиве: ");
  scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  printf("Введите элементы: ");
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (!a[i] && k == -1) {
      k = i;
    }
  }
  if (k == -1)
    k = n;
  quick_sort(a, 0, k - 1);
  for (int i = k; i < n; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1208 <main+0xb8>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7d(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11f5 <main+0xa5>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f5 <main+0xa5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11fa <main+0xaa>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <main+0x5c>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1218 <main+0xc8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1060 <quick_sort@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1258 <main+0x108>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122f <main+0xdf>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1292 <main+0x142>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    125f <main+0x10f>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    11f6 <main+0xa6>
mov    $0xffffffff,%ebp
xor    %r13d,%r13d
lea    0xe9d(%rip),%r14
mov    %r15,%rbx
jmp    11d5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13
movslq 0x4(%rsp),%rax
add    $0x4,%rbx
mov    %r12d,%ebp
cmp    %rax,%r13
jge    11f0 <main+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %ebp,%eax
not    %eax
or     (%rbx),%eax
mov    %r13d,%r12d
je     11c0 <main+0x70>
mov    %ebp,%r12d
jmp    11c0 <main+0x70>
cmp    $0xffffffff,%r12d
jne    11f9 <main+0xa9>
mov    %eax,%r12d
lea    -0x1(%r12),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <quick_sort@plt>
mov    0x4(%rsp),%eax
cmp    %eax,%r12d
jge    1236 <main+0xe6>
movslq %r12d,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x0,(%r15,%rcx,4)
add    $0x1,%rcx
movslq 0x4(%rsp),%rax
cmp    %rax,%rcx
jl     1220 <main+0xd0>
test   %eax,%eax
jle    126c <main+0x11c>
lea    0xe2f(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     1250 <main+0x100>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [75 x i8] c"\D0\92\D0\B2\D0\B5\D0\B4\D0\B8\D1\82\D0\B5 \D0\BA\D0\BE\D0\BB\D0\B8\D1\87\D0\B5\D1\81\D1\82\D0\B2\D0\BE \D1\8D\D0\BB\D0\B5\D0\BC\D0\B5\D0\BD\D1\82\D0\BE\D0\B2 \D0\B2 \D0\BC\D0\B0\D1\81\D1\81\D0\B8\D0\B2\D0\B5: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\D0\92\D0\B2\D0\B5\D0\B4\D0\B8\D1\82\D0\B5 \D1\8D\D0\BB\D0\B5\D0\BC\D0\B5\D0\BD\D1\82\D1\8B: \00"
@.str.3 = [4 x i8] c"%d \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 -1, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %17
17: ; preds = %39, %0
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %42
21: ; preds = %17
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = load i32*, i32** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %21
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i32, i32* %5
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %33, %21
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %17
42: ; preds = %17
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = load i32, i32* %2
store i32 %46, i32* %4
br label %47
47: ; preds = %45, %42
%48 = load i32*, i32** %3
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = call i32 @quick_sort(i32* %48, i32 0, i32 %50)
%52 = load i32, i32* %4
store i32 %52, i32* %6
br label %53
53: ; preds = %62, %47
%54 = load i32, i32* %6
%55 = load i32, i32* %2
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load i32*, i32** %3
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 0, i32* %61
br label %62
62: ; preds = %57
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %53
65: ; preds = %53
store i32 0, i32* %7
br label %66
66: ; preds = %77, %65
%67 = load i32, i32* %7
%68 = load i32, i32* %2
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %80
70: ; preds = %66
%71 = load i32*, i32** %3
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %70
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %66
80: ; preds = %66
%81 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [75 x i8] c"\D0\92\D0\B2\D0\B5\D0\B4\D0\B8\D1\82\D0\B5 \D0\BA\D0\BE\D0\BB\D0\B8\D1\87\D0\B5\D1\81\D1\82\D0\B2\D0\BE \D1\8D\D0\BB\D0\B5\D0\BC\D0\B5\D0\BD\D1\82\D0\BE\D0\B2 \D0\B2 \D0\BC\D0\B0\D1\81\D1\81\D0\B8\D0\B2\D0\B5: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"\D0\92\D0\B2\D0\B5\D0\B4\D0\B8\D1\82\D0\B5 \D1\8D\D0\BB\D0\B5\D0\BC\D0\B5\D0\BD\D1\82\D1\8B: \00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 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 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %24, label %14
12: ; preds = %24
%13 = icmp eq i32 %34, -1
br i1 %13, label %14, label %16
14: ; preds = %0, %12
%15 = phi i32 [ %36, %12 ], [ %10, %0 ]
br label %16
16: ; preds = %12, %14
%17 = phi i32 [ %15, %14 ], [ %34, %12 ]
%18 = add nsw i32 %17, -1
%19 = call i32 @quick_sort(i32* %8, i32 0, i32 %18)
%20 = load i32, i32* %1
%21 = icmp slt i32 %17, %20
br i1 %21, label %22, label %39
22: ; preds = %16
%23 = sext i32 %17 to i64
br label %42
24: ; preds = %0, %24
%25 = phi i64 [ %35, %24 ], [ 0, %0 ]
%26 = phi i32 [ %34, %24 ], [ -1, %0 ]
%27 = getelementptr inbounds i32, i32* %8, i64 %25
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %27)
%29 = load i32, i32* %27
%30 = icmp eq i32 %29, 0
%31 = icmp eq i32 %26, -1
%32 = select i1 %30, i1 %31, i1 false
%33 = trunc i64 %25 to i32
%34 = select i1 %32, i32 %33, i32 %26
%35 = add nuw nsw i64 %25, 1
%36 = load i32, i32* %1
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %24, label %12
39: ; preds = %42, %16
%40 = phi i32 [ %20, %16 ], [ %46, %42 ]
%41 = icmp sgt i32 %40, 0
br i1 %41, label %51, label %49
42: ; preds = %22, %42
%43 = phi i64 [ %23, %22 ], [ %45, %42 ]
%44 = getelementptr inbounds i32, i32* %8, i64 %43
store i32 0, i32* %44
%45 = add nsw i64 %43, 1
%46 = load i32, i32* %1
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %45, %47
br i1 %48, label %42, label %39
49: ; preds = %51, %39
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %39, %51
%52 = phi i64 [ %56, %51 ], [ 0, %39 ]
%53 = getelementptr inbounds i32, i32* %8, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = add nuw nsw i64 %52, 1
%57 = load i32, i32* %1
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %56, %58
br i1 %59, label %51, label %49
}