#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("Move non-zero to left and zero's to right\n");
  int arr[] = {1, 0, 0, 0, 1, 2, 3, 0, 0, 2};
  int len = (int)(sizeof(arr) / sizeof(int));
  printf("Given :");
  for (int i = 0; i < len; i++) {
    printf("%d ", arr[i]);
  }
  printf("\n");
  for (int i = 0; i < len; i++) {
    if (arr[i] != 0) {
      continue;
    }
    int j = i + 1;
    while (j < len) {
      if (arr[j] != 0) {
        int temp = arr[j];
        arr[j] = arr[i];
        arr[i] = temp;
        break;
      }
      j++;
    }
  }
  printf("Output: ");
  for (int i = 0; i < len; i++) {
    printf("%d ", arr[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x1,-0x30(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0xa,-0x34(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11bc <main+0x9c>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118c <main+0x6c>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1261 <main+0x141>
movslq -0x3c(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
je     11f1 <main+0xd1>
jmp    1253 <main+0x133>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    124e <main+0x12e>
movslq -0x40(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
je     1240 <main+0x120>
movslq -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x44(%rbp)
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x40(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x44(%rbp),%ecx
movslq -0x3c(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    124e <main+0x12e>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11fa <main+0xda>
jmp    1253 <main+0x133>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d1 <main+0xb1>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12a6 <main+0x186>
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1276 <main+0x156>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xed6(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x1,(%rsp)
movabs $0x200000001,%rax
mov    %rax,0x10(%rsp)
movl   $0x3,0x18(%rsp)
movl   $0x2,0x24(%rsp)
lea    0xe7a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe72(%rip),%r14
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
test   %ebp,%ebp
jne    1270 <main+0x140>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%rcx
je     1270 <main+0x140>
mov    (%rsp,%rcx,4),%edx
add    $0x1,%rcx
test   %edx,%edx
je     1250 <main+0x120>
movl   $0x0,-0x4(%rsp,%rcx,4)
mov    %edx,(%rsp,%rbx,4)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    $0xa,%rbx
je     1287 <main+0x157>
mov    (%rsp,%rbx,4),%ebp
add    $0x1,%rax
test   %ebp,%ebp
jne    1270 <main+0x140>
jmp    1240 <main+0x110>
lea    0xd7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%esi
lea    0xd69(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Move non-zero to left and zero's to right\0A\00"
@.str.1 = [8 x i8] c"Given :\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [9 x i8] c"Output: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%10 = bitcast [10 x i32]* %2 to i8*
%11 = bitcast i8* %10 to [10 x i32]*
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 0
store i32 1, i32* %12
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 4
store i32 1, i32* %13
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 5
store i32 2, i32* %14
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 6
store i32 3, i32* %15
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 9
store i32 2, i32* %16
store i32 10, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %18
18: ; preds = %28, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %33
33: ; preds = %77, %31
%34 = load i32, i32* %5
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %80
37: ; preds = %33
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %77
44: ; preds = %37
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %47
47: ; preds = %73, %44
%48 = load i32, i32* %6
%49 = load i32, i32* %3
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %76
51: ; preds = %47
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %73
57: ; preds = %51
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %59
%61 = load i32, i32* %60
store i32 %61, i32* %7
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %67
store i32 %65, i32* %68
%69 = load i32, i32* %7
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %71
store i32 %69, i32* %72
br label %76
73: ; preds = %51
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %47
76: ; preds = %57, %47
br label %77
77: ; preds = %76, %43
%78 = load i32, i32* %5
%79 = add nsw i32 %78, 1
store i32 %79, i32* %5
br label %33
80: ; preds = %33
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %82
82: ; preds = %92, %80
%83 = load i32, i32* %8
%84 = load i32, i32* %3
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %95
86: ; preds = %82
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %86
%93 = load i32, i32* %8
%94 = add nsw i32 %93, 1
store i32 %94, i32* %8
br label %82
95: ; preds = %82
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"Given :\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.4 = [9 x i8] c"Output: \00"
@str = [42 x i8] c"Move non-zero to left and zero's to right\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%3 = bitcast [10 x i32]* %1 to i8*
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
store i32 1, i32* %4
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
store i32 1, i32* %5
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
store i32 2, i32* %6
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
store i32 3, i32* %7
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
store i32 2, i32* %8
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%20 = tail call i32 @putchar(i32 10)
br label %49
21: ; preds = %65
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%28 = load i32, i32* %4
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %25
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %24
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %5
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %7
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %23
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %22
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %8
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = tail call i32 @putchar(i32 10)
ret i32 0
49: ; preds = %68, %0
%50 = phi i32 [ 1, %0 ], [ %70, %68 ]
%51 = phi i64 [ 0, %0 ], [ %66, %68 ]
%52 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %51
%53 = icmp eq i32 %50, 0
br i1 %53, label %54, label %65
54: ; preds = %49, %58
%55 = phi i64 [ %56, %58 ], [ %51, %49 ]
%56 = add nuw nsw i64 %55, 1
%57 = icmp eq i64 %55, 9
br i1 %57, label %65, label %58
58: ; preds = %54
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %56
%60 = load i32, i32* %59
%61 = icmp eq i32 %60, 0
br i1 %61, label %54, label %62
62: ; preds = %58
%63 = and i64 %56, 4294967295
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %63
store i32 0, i32* %64
store i32 %60, i32* %52
br label %65
65: ; preds = %54, %62, %49
%66 = add nuw nsw i64 %51, 1
%67 = icmp eq i64 %66, 10
br i1 %67, label %21, label %68
68: ; preds = %65
%69 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %66
%70 = load i32, i32* %69
br label %49
}