#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*/ buffer_small;
typedef int /*<<< orphan*/ buffer_big;

/* Variables and functions */
int /*<<< orphan*/ is_valid_cstring(char const *, int);
int /*<<< orphan*/ memset_c(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
int main(void) {
  const char helloworld[] = "Hello, world!";
  char buffer_small[6];
  char buffer_big[42];
  memset_c(buffer_small, 0, sizeof(buffer_small));
  memset_c(buffer_big, 0, sizeof(buffer_big));
  if (!is_valid_cstring(helloworld, 13)) {
    return 0;
  }
  strlcpy(buffer_small, helloworld, sizeof(buffer_small));
  if (!is_valid_cstring(helloworld, 13)) {
    return 0;
  }
  strlcpy(buffer_big, helloworld, sizeof(buffer_big));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xeb8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xeb2(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset_c@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x2a,%edx
call   1050 <memset_c@plt>
lea    -0x12(%rbp),%rdi
mov    $0xd,%esi
call   1030 <is_valid_cstring@plt>
cmp    $0x0,%eax
jne    11a1 <main+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11ef <main+0xbf>
lea    -0x18(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x6,%edx
call   1040 <strlcpy@plt>
lea    -0x12(%rbp),%rdi
mov    $0xd,%esi
call   1030 <is_valid_cstring@plt>
cmp    $0x0,%eax
jne    11d6 <main+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11ef <main+0xbf>
lea    -0x50(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x2a,%edx
call   1040 <strlcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0xe(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,0x8(%rsp)
lea    0x1a(%rsp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset_c@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x2a,%edx
call   1050 <memset_c@plt>
lea    0x8(%rsp),%rdi
mov    $0xd,%esi
call   1030 <is_valid_cstring@plt>
test   %eax,%eax
je     11c4 <main+0x94>
lea    0x1a(%rsp),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x6,%edx
call   1040 <strlcpy@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <is_valid_cstring@plt>
test   %eax,%eax
je     11c4 <main+0x94>
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x2a,%edx
call   1040 <strlcpy@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.helloworld = [14 x i8] c"Hello, world!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca [6 x i8]
%4 = alloca [42 x i8]
store i32 0, i32* %1
%5 = bitcast [14 x i8]* %2 to i8*
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset_c(i8* %6, i32 0, i32 6)
%8 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 0
%9 = call i32 @memset_c(i8* %8, i32 0, i32 42)
%10 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%11 = call i32 @is_valid_cstring(i8* %10, i32 13)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %0
store i32 0, i32* %1
br label %26
14: ; preds = %0
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%17 = call i32 @strlcpy(i8* %15, i8* %16, i32 6)
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%19 = call i32 @is_valid_cstring(i8* %18, i32 13)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
store i32 0, i32* %1
br label %26
22: ; preds = %14
%23 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%25 = call i32 @strlcpy(i8* %23, i8* %24, i32 42)
store i32 0, i32* %1
br label %26
26: ; preds = %22, %21, %13
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@__const.main.helloworld = [14 x i8] c"Hello, world!\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [6 x i8]
%3 = alloca [42 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [42 x i8], [42 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset_c(i8* %5, i32 0, i32 6)
%8 = call i32 @memset_c(i8* %6, i32 0, i32 42)
%9 = call i32 @is_valid_cstring(i8* %4, i32 13)
%10 = icmp eq i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %0
%12 = call i32 @strlcpy(i8* %5, i8* %4, i32 6)
%13 = call i32 @is_valid_cstring(i8* %4, i32 13)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @strlcpy(i8* %6, i8* %4, i32 42)
br label %17
17: ; preds = %11, %0, %15
ret i32 0
}