#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 password_to_key(char *, int, unsigned char *, int);
int read_passkey(unsigned char *, int);
int strlen(char *);
int gg_pass_cb(char *buf, int size, int rwflag __attribute__((unused)),
               void *u __attribute__((unused))) {
  int ret;
  ret = read_passkey((unsigned char *)buf, size);
  if (ret <= 0)
    return 0;
  ret = password_to_key(buf, ret, (unsigned char *)buf, size);
  if (ret)
    return 0;
  return strlen(buf);
}


x86 assembly (clang, -O0):
<gg_pass_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)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <read_passkey@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     116b <gg_pass_cb+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <gg_pass_cb+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1040 <password_to_key@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1197 <gg_pass_cb+0x67>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <gg_pass_cb+0x73>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gg_pass_cb>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <read_passkey@plt>
test   %eax,%eax
jle    1154 <gg_pass_cb+0x24>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1040 <password_to_key@plt>
test   %eax,%eax
je     115d <gg_pass_cb+0x2d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strlen@plt>

LLVM IR (-O0):
define i32 @gg_pass_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 i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @read_passkey(i8* %11, i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 0, i32* %5
br label %29
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i32, i32* %10
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @password_to_key(i8* %18, i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 0, i32* %5
br label %29
26: ; preds = %17
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %5
br label %29
29: ; preds = %26, %25, %16
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @gg_pass_cb(i8* %0, i32 %1, i32 %2, i8* nocapture readnone %3) {
%5 = tail call i32 @read_passkey(i8* %0, i32 %1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32 @password_to_key(i8* %0, i32 %5, i8* %0, i32 %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
br label %12
12: ; preds = %7, %4, %10
%13 = phi i32 [ %11, %10 ], [ 0, %4 ], [ 0, %7 ]
ret i32 %13
}