#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*/ uint8_t;
typedef int int8_t;

/* Variables and functions */
void move_nonzero_first(uint8_t row[4]) {
  int8_t start_of_zeros = 0;
  for (int8_t i = 0; i < 4; ++i) {
    if (row[i] == 0)
      continue;
    uint8_t t = row[i];
    row[i] = 0;
    row[start_of_zeros++] = t;
  }
}


x86 assembly (clang, -O0):
<move_nonzero_first>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    117a <move_nonzero_first+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1137 <move_nonzero_first+0x37>
jmp    116c <move_nonzero_first+0x6c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1116 <move_nonzero_first+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_nonzero_first>:
mov    (%rdi),%edx
mov    0x4(%rdi),%ecx
xor    %eax,%eax
test   %edx,%edx
setne  %sil
test   %ecx,%ecx
je     1128 <move_nonzero_first+0x28>
xor    %esi,%esi
test   %edx,%edx
setne  %sil
movl   $0x0,0x4(%rdi)
lea    0x1(%rsi),%eax
mov    %ecx,(%rdi,%rsi,4)
jmp    112b <move_nonzero_first+0x2b>
mov    %sil,%al
mov    0x8(%rdi),%ecx
test   %ecx,%ecx
je     1141 <move_nonzero_first+0x41>
movl   $0x0,0x8(%rdi)
mov    %eax,%edx
add    $0x1,%eax
mov    %ecx,(%rdi,%rdx,4)
mov    0xc(%rdi),%ecx
test   %ecx,%ecx
je     1154 <move_nonzero_first+0x54>
movl   $0x0,0xc(%rdi)
mov    %eax,%eax
mov    %ecx,(%rdi,%rax,4)
ret

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

LLVM IR (-O2):
define void @move_nonzero_first(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp ne i32 %2, 0
%4 = zext i1 %3 to i32
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
store i32 0, i32* %5
%9 = select i1 %3, i32 2, i32 1
%10 = zext i1 %3 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
store i32 %6, i32* %11
br label %12
12: ; preds = %8, %1
%13 = phi i32 [ %4, %1 ], [ %9, %8 ]
%14 = getelementptr inbounds i32, i32* %0, i64 2
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
store i32 0, i32* %14
%18 = add nuw nsw i32 %13, 1
%19 = zext i32 %13 to i64
%20 = getelementptr inbounds i32, i32* %0, i64 %19
store i32 %15, i32* %20
br label %21
21: ; preds = %17, %12
%22 = phi i32 [ %13, %12 ], [ %18, %17 ]
%23 = getelementptr inbounds i32, i32* %0, i64 3
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
store i32 0, i32* %23
%27 = zext i32 %22 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %26, %21
ret void
}