#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ stderr;
int strlen(void *);
int pem_passwd_cb_fun(char *buf, int size, int rwflag, void *password) {
  int i;
  fprintf(stderr, "In pem_passwd_cb_fun\r\n");
  if (!password)
    return 0;
  i = strlen(password);
  if (i < size) {
    fprintf(stderr, "Got FULL pwd %d(%d) chars\r\n", i, size);
    memcpy(buf, (char *)password, i + 1);
    return i + 1;
  } else {
    fprintf(stderr, "Got TO LONG pwd %d(%d) chars\r\n", i, size);
    return 0;
  }
}


x86 assembly (clang, -O0):
<pem_passwd_cb_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1174 <pem_passwd_cb_fun+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11ee <pem_passwd_cb_fun+0xbe>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ca <pem_passwd_cb_fun+0x9a>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <pem_passwd_cb_fun+0xbe>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pem_passwd_cb_fun>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2e99(%rip),%r12
mov    (%r12),%edi
lea    0xeae(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14,%r14
je     11aa <pem_passwd_cb_fun+0x7a>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    (%r12),%edi
cmp    %ebp,%eax
jge    1196 <pem_passwd_cb_fun+0x66>
lea    0xe9e(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
jmp    11aa <pem_passwd_cb_fun+0x7a>
lea    0xe96(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"In pem_passwd_cb_fun\0D\0A\00"
@.str.1 = [28 x i8] c"Got FULL pwd %d(%d) chars\0D\0A\00"
@.str.2 = [31 x i8] c"Got TO LONG pwd %d(%d) chars\0D\0A\00"
define i32 @pem_passwd_cb_fun(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 i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %4
store i32 0, i32* %5
br label %39
16: ; preds = %4
%17 = load i8*, i8** %9
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i32, i32* %10
%25 = load i32, i32* %7
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i8*, i8** %6
%28 = load i8*, i8** %9
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
%31 = call i32 @memcpy(i8* %27, i8* %28, i32 %30)
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %39
34: ; preds = %16
%35 = load i32, i32* @stderr
%36 = load i32, i32* %10
%37 = load i32, i32* %7
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
store i32 0, i32* %5
br label %39
39: ; preds = %34, %22, %15
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"In pem_passwd_cb_fun\0D\0A\00"
@.str.1 = [28 x i8] c"Got FULL pwd %d(%d) chars\0D\0A\00"
@.str.2 = [31 x i8] c"Got TO LONG pwd %d(%d) chars\0D\0A\00"
define i32 @pem_passwd_cb_fun(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %3, null
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %3)
%10 = icmp slt i32 %9, %1
%11 = load i32, i32* @stderr
br i1 %10, label %12, label %16
12: ; preds = %8
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %1)
%14 = add nsw i32 %9, 1
%15 = tail call i32 @memcpy(i8* %0, i8* %3, i32 %14)
br label %18
16: ; preds = %8
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %1)
br label %18
18: ; preds = %4, %16, %12
%19 = phi i32 [ %14, %12 ], [ 0, %16 ], [ 0, %4 ]
ret i32 %19
}