void main() {
  char str[50] = "This is a test program for memset().";
  printf("%s\n", str);
  memset(str + 10, '*', 4 * sizeof(char));
  printf("%s\n", str);
  int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  print_array(arr, 10);
  memset(arr + 3, 0, sizeof(int) * 3);
  print_array(arr, 10);
  int arr2[10] = {0};
  memset(arr2, 1, sizeof(int) * 5);
  print_array(arr2, 10);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x40(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rsi
lea    0xefd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
add    $0xa,%rdi
mov    $0x2a,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rsi
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <print_array@plt>
lea    -0x70(%rbp),%rdi
add    $0xc,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <print_array@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x1,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0xa0(%rbp),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <print_array@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xa0,%rsp
movaps 0xf01(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movw   $0x0,0x90(%rsp)
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
movl   $0x2a2a2a2a,0x6a(%rsp)
2a
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0xef3(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebb(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <print_array@plt>
movq   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <print_array@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movq   $0x0,0x50(%rsp)
movaps 0xe1d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x1010101,0x40(%rsp)
01
lea    0x30(%rsp),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <print_array@plt>
add    $0xa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str = [50 x i8] c"This is a test program for memset().\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"%s\0A\00"
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
define void @main() {
%1 = alloca [50 x i8]
%2 = alloca [10 x i32]
%3 = alloca [10 x i32]
%4 = bitcast [50 x i8]* %1 to i8*
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 10
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = bitcast [10 x i32]* %2 to i8*
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%13 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %12, i32 10)
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%15 = getelementptr inbounds i32, i32* %14, i64 3
%16 = bitcast i32* %15 to i8*
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%18 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %17, i32 10)
%19 = bitcast [10 x i32]* %3 to i8*
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%21 = bitcast i32* %20 to i8*
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%23 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %22, i32 10)
ret void
}

LLVM IR (-O2):
@__const.main.str = [50 x i8] c"This is a test program for memset().\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
define void @main() {
%1 = alloca [50 x i8]
%2 = alloca [10 x i32]
%3 = alloca [10 x i32]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = call i32 @puts(i8* %4)
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 10
%7 = bitcast i8* %6 to i32*
store i32 707406378, i32* %7
%8 = call i32 @puts(i8* %4)
%9 = bitcast [10 x i32]* %2 to i8*
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%11 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %10, i32 10)
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 3
%13 = bitcast i32* %12 to i8*
%14 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %10, i32 10)
%15 = bitcast [10 x i32]* %3 to i8*
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%17 = bitcast i32* %16 to i8*
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%19 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @print_array to i32 (i32*, i32, ...)*)(i32* %18, i32 10)
ret void
}