#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 */
scalar_t__ do_getline(char *, char *, int, int);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strlen(char const *);
int ftp_lite_login(const char *service, char *name, int namelen, char *pass,
                   int passlen) {
  char *prompt;
  prompt = malloc(strlen(service) + 10);
  if (!prompt)
    return 0;
  sprintf(prompt, "%s login: ", service);
  int result = do_getline(prompt, name, namelen, 1) &&
               do_getline("password: ", pass, passlen, 0);
  free(prompt);
  return result;
}


x86 assembly (clang, -O0):
<ftp_lite_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0xa,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119b <ftp_lite_login+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    120f <ftp_lite_login+0xbf>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%ecx
call   1070 <do_getline@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x3d(%rbp)
je     11f5 <ftp_lite_login+0xa5>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xe27(%rip),%rdi
xor    %ecx,%ecx
call   1070 <do_getline@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_lite_login>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
call   1040 <strlen@plt>
lea    0xa(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c9 <ftp_lite_login+0x79>
mov    %rax,%rbx
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    $0x1,%ecx
call   1070 <do_getline@plt>
test   %rax,%rax
je     11cd <ftp_lite_login+0x7d>
lea    0xe5a(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1070 <do_getline@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    11cf <ftp_lite_login+0x7f>
xor    %ebp,%ebp
jmp    11d7 <ftp_lite_login+0x87>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s login: \00"
@.str.1 = [11 x i8] c"password: \00"
define i32 @ftp_lite_login(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 10
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %12
%18 = load i8*, i8** %12
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %5
store i32 0, i32* %6
br label %41
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = load i8*, i8** %7
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %12
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = call i64 @do_getline(i8* %25, i8* %26, i32 %27, i32 1)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %21
%31 = load i8*, i8** %10
%32 = load i32, i32* %11
%33 = call i64 @do_getline(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 %32, i32 0)
%34 = icmp ne i64 %33, 0
br label %35
35: ; preds = %30, %21
%36 = phi i1 [ false, %21 ], [ %34, %30 ]
%37 = zext i1 %36 to i32
store i32 %37, i32* %13
%38 = load i8*, i8** %12
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* %13
store i32 %40, i32* %6
br label %41
41: ; preds = %35, %20
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s login: \00"
@.str.1 = [11 x i8] c"password: \00"
define i32 @ftp_lite_login(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 10
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %21, label %10
10: ; preds = %5
%11 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i64 @do_getline(i8* %8, i8* %1, i32 %2, i32 1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = tail call i64 @do_getline(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %4, i32 0)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ 0, %10 ], [ %17, %14 ]
%20 = tail call i32 @free(i8* %8)
br label %21
21: ; preds = %5, %18
%22 = phi i32 [ %19, %18 ], [ 0, %5 ]
ret i32 %22
}