#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 /*<<< orphan*/, int);
size_t strlcpy(char *, void *, int);
int tls_password_cb(char *buf, int size, int rwflag, void *u) {
  size_t len;
  if (u == NULL) {
    memset(buf, 0, size);
    return (0);
  }
  if ((len = strlcpy(buf, u, size)) >= (size_t)size)
    return (0);
  return (len);
}


x86 assembly (clang, -O0):
<tls_password_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115b <tls_password_cb+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x4(%rbp)
jmp    118f <tls_password_cb+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strlcpy@plt>
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jb     1188 <tls_password_cb+0x68>
movl   $0x0,-0x4(%rbp)
jmp    118f <tls_password_cb+0x6f>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tls_password_cb>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rcx,%rcx
je     1144 <tls_password_cb+0x24>
mov    %rcx,%rsi
mov    %ebp,%edx
call   1040 <strlcpy@plt>
mov    %rax,%rbx
movslq %ebp,%rax
xor    %ecx,%ecx
cmp    %rax,%rbx
cmovae %ecx,%ebx
jmp    114f <tls_password_cb+0x2f>
xor    %ebx,%ebx
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tls_password_cb(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %9
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
store i32 0, i32* %5
br label %29
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i8*, i8** %9
%20 = load i32, i32* %7
%21 = call i64 @strlcpy(i8* %18, i8* %19, i32 %20)
store i64 %21, i64* %10
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = icmp uge i64 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 0, i32* %5
br label %29
26: ; preds = %17
%27 = load i64, i64* %10
%28 = trunc i64 %27 to i32
store i32 %28, i32* %5
br label %29
29: ; preds = %26, %25, %13
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @tls_password_cb(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
br label %14
8: ; preds = %4
%9 = tail call i64 @strlcpy(i8* %0, i8* %3, i32 %1)
%10 = sext i32 %1 to i64
%11 = icmp ult i64 %9, %10
%12 = trunc i64 %9 to i32
%13 = select i1 %11, i32 %12, i32 0
br label %14
14: ; preds = %8, %6
%15 = phi i32 [ 0, %6 ], [ %13, %8 ]
ret i32 %15
}