#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*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *);
int test_memset(void) {
  char value0[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  printf("\tmemset");
  memset(value0, 2, 5);
  if (value0[0] != 2)
    return 1;
  if (value0[4] != 2)
    return 1;
  if (value0[5] != 1)
    return 1;
  memset(value0, 1, 0);
  if (value0[0] != 2)
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_memset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xece(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    $0x2,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
movsbl -0xe(%rbp),%eax
cmp    $0x2,%eax
je     1176 <test_memset+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <test_memset+0xc4>
movsbl -0xa(%rbp),%eax
cmp    $0x2,%eax
je     118f <test_memset+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <test_memset+0xc4>
movsbl -0x9(%rbp),%eax
cmp    $0x1,%eax
je     11a8 <test_memset+0x88>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <test_memset+0xc4>
lea    -0xe(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <memset@plt>
movsbl -0xe(%rbp),%eax
cmp    $0x2,%eax
je     11d1 <test_memset+0xb1>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <test_memset+0xc4>
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memset>:
push   %rbx
sub    $0x10,%rsp
movabs $0x101010101010101,%rax
01 01 01
mov    %rax,(%rsp)
movw   $0x101,0x8(%rsp)
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x2,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
cmpb   $0x2,(%rsp)
mov    $0x1,%ebx
jne    11a9 <test_memset+0x79>
cmpb   $0x2,0x4(%rsp)
jne    11a9 <test_memset+0x79>
cmpb   $0x1,0x5(%rsp)
jne    11a9 <test_memset+0x79>
mov    %rsp,%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <memset@plt>
cmpb   $0x2,(%rsp)
jne    11a9 <test_memset+0x79>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_memset.value0 = [10 x i8] c"\01\01\01\01\01\01\01\01\01\01"
@.str = [8 x i8] c"\09memset\00"
@.str.1 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_memset() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = bitcast [10 x i8]* %2 to i8*
%4 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 2, i32 5)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 1, i32* %1
br label %34
12: ; preds = %0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 1, i32* %1
br label %34
18: ; preds = %12
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %1
br label %34
24: ; preds = %18
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 1, i32 0)
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 2
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %1
br label %34
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %34
34: ; preds = %32, %31, %23, %17, %11
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"\09memset\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_memset() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @memset(i8* %2, i32 2, i32 5)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 2
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 4
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 2
%10 = select i1 %6, i1 %9, i1 false
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 5
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 1
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = call i32 @memset(i8* %2, i32 1, i32 0)
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %15, %0, %19
%22 = phi i32 [ 0, %19 ], [ 1, %0 ], [ 1, %15 ]
ret i32 %22
}