#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*/ clang_analyzer_eval(int);
int /*<<< orphan*/ memset(char *, char, int);
int strlen(char *);
void memset2_char_array_null() {
  char str[] = "abcd";
  clang_analyzer_eval(strlen(str) == 4);
  memset(str, '\0', strlen(str) + 1);
  clang_analyzer_eval(strlen(str) == 0);
  clang_analyzer_eval(str[2] == 0);
}


x86 assembly (clang, -O0):
<memset2_char_array_null>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xec2(%rip),%eax
mov    %eax,-0x5(%rbp)
mov    0xebd(%rip),%al
mov    %al,-0x1(%rbp)
lea    -0x5(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <clang_analyzer_eval@plt>
lea    -0x5(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x5(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x5(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <clang_analyzer_eval@plt>
movsbl -0x3(%rbp),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <clang_analyzer_eval@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memset2_char_array_null>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x64636261,0x8(%rsp)
64
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1050 <clang_analyzer_eval@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <clang_analyzer_eval@plt>
xor    %edi,%edi
cmpb   $0x0,0xa(%rsp)
sete   %dil
call   1050 <clang_analyzer_eval@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.memset2_char_array_null.str = [5 x i8] c"abcd\00"
define void @memset2_char_array_null() {
%1 = alloca [5 x i8]
%2 = bitcast [5 x i8]* %1 to i8*
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = icmp eq i32 %4, 4
%6 = zext i1 %5 to i32
%7 = call i32 @clang_analyzer_eval(i32 %6)
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = call i32 @memset(i8* %8, i8 signext 0, i32 %11)
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @clang_analyzer_eval(i32 %16)
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @clang_analyzer_eval(i32 %22)
ret void
}

LLVM IR (-O2):
@__const.memset2_char_array_null.str = [5 x i8] c"abcd\00"
define void @memset2_char_array_null() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = icmp eq i32 %3, 4
%5 = zext i1 %4 to i32
%6 = call i32 @clang_analyzer_eval(i32 %5)
%7 = call i32 @strlen(i8* %2)
%8 = add nsw i32 %7, 1
%9 = call i32 @memset(i8* %2, i8 signext 0, i32 %8)
%10 = call i32 @strlen(i8* %2)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @clang_analyzer_eval(i32 %12)
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 2
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @clang_analyzer_eval(i32 %17)
ret void
}