#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ ftpabort();
int ready(char *, int /*<<< orphan*/);
FILE *ftpls(void) {
  int fd;
  FILE *fp;
  fd = ready("LIST", 0);
  if (fd == -1)
    return NULL;
  fp = fdopen(fd, "r");
  if (!fp) {
    (void)close(fd);
    ftpabort();
    return NULL;
  }
  return fp;
}


x86 assembly (clang, -O0):
<ftpls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
xor    %esi,%esi
call   1030 <ready@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1170 <ftpls+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <ftpls+0x72>
mov    -0xc(%rbp),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <ftpls+0x6a>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1060 <ftpabort@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <ftpls+0x72>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftpls>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <ready@plt>
cmp    $0xffffffff,%eax
je     1180 <ftpls+0x40>
mov    %eax,%ebp
lea    0xea4(%rip),%rsi
mov    %eax,%edi
call   1050 <fdopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <ftpls+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <ftpabort@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"LIST\00"
@.str.1 = [2 x i8] c"r\00"
define i32* @ftpls() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32*
%4 = call i32 @ready(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %0
store i32* null, i32** %1
br label %19
8: ; preds = %0
%9 = load i32, i32* %2
%10 = call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = call i32 (...) @ftpabort()
store i32* null, i32** %1
br label %19
17: ; preds = %8
%18 = load i32*, i32** %3
store i32* %18, i32** %1
br label %19
19: ; preds = %17, %13, %7
%20 = load i32*, i32** %1
ret i32* %20
}

LLVM IR (-O2):
@.str = [5 x i8] c"LIST\00"
@.str.1 = [2 x i8] c"r\00"
define noalias i32* @ftpls() {
%1 = tail call i32 @ready(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = icmp eq i32 %1, -1
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = tail call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @close(i32 %1)
%8 = tail call i32 (...) @ftpabort()
br label %9
9: ; preds = %3, %0, %6
%10 = phi i32* [ null, %6 ], [ null, %0 ], [ %4, %3 ]
ret i32* %10
}