#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 void *uint8_t;

/* Variables and functions */
int memset_rest_bytes(uint8_t *ptr, uint8_t c, size_t len) {
  switch (len) {
  case 3:
    *ptr++ = c;
  case 2:
    *ptr++ = c;
  case 1:
    *ptr++ = c;
  }
}


x86 assembly (clang, -O0):
<memset_rest_bytes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0x1,%rax
je     1179 <memset_rest_bytes+0x79>
jmp    1127 <memset_rest_bytes+0x27>
mov    -0x28(%rbp),%rax
sub    $0x2,%rax
je     1163 <memset_rest_bytes+0x63>
jmp    113a <memset_rest_bytes+0x3a>
mov    -0x28(%rbp),%rax
sub    $0x3,%rax
jne    118f <memset_rest_bytes+0x8f>
jmp    114d <memset_rest_bytes+0x4d>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<memset_rest_bytes>:
cmp    $0x1,%rdx
je     1120 <memset_rest_bytes+0x20>
cmp    $0x2,%rdx
je     1119 <memset_rest_bytes+0x19>
cmp    $0x3,%rdx
jne    1123 <memset_rest_bytes+0x23>
mov    %rsi,(%rdi)
add    $0x8,%rdi
mov    %rsi,(%rdi)
add    $0x8,%rdi
mov    %rsi,(%rdi)
ret

LLVM IR (-O0):
define i32 @memset_rest_bytes(i8** %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i64, i64* %7
switch i64 %8, label %21 [
i64 3, label %9
i64 2, label %13
i64 1, label %17
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i32 1
store i8** %12, i8*** %5
store i8* %10, i8** %11
br label %13
13: ; preds = %3, %9
%14 = load i8*, i8** %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %5
store i8* %14, i8** %15
br label %17
17: ; preds = %3, %13
%18 = load i8*, i8** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
store i8* %18, i8** %19
br label %21
21: ; preds = %17, %3
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
define i32 @memset_rest_bytes(i8** nocapture writeonly %0, i8* %1, i64 %2) {
switch i64 %2, label %11 [
i64 3, label %4
i64 2, label %6
i64 1, label %9
]
4: ; preds = %3
%5 = getelementptr inbounds i8*, i8** %0, i64 1
store i8* %1, i8** %0
br label %6
6: ; preds = %3, %4
%7 = phi i8** [ %0, %3 ], [ %5, %4 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* %1, i8** %7
br label %9
9: ; preds = %3, %6
%10 = phi i8** [ %0, %3 ], [ %8, %6 ]
store i8* %1, i8** %10
br label %11
11: ; preds = %9, %3
ret i32 undef
}