#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ dologout(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ ftpd_pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ftpd_popen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ lreply(int, char *, char const *);
int /*<<< orphan*/ perror_reply(int, char const *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ reply(int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ *stdout;
void statfilecmd(const char *filename) {
  FILE *fin;
  int c;
  char line[2048];
  (void)snprintf(line, sizeof(line), "/bin/ls -lgA %s", filename);
  fin = ftpd_popen(line, "r");
  lreply(211, "status of %s:", filename);
  while ((c = getc(fin)) != EOF) {
    if (c == '\n') {
      if (ferror(stdout)) {
        perror_reply(421, "control connection");
        (void)ftpd_pclose(fin);
        dologout(1);
      }
      if (ferror(fin)) {
        perror_reply(551, filename);
        (void)ftpd_pclose(fin);
        return;
      }
      (void)putc('\r', stdout);
    }
    (void)putc(c, stdout);
  }
  (void)ftpd_pclose(fin);
  reply(211, "End of Status");
}


x86 assembly (clang, -O0):
<statfilecmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x800,%esi
lea    0xe3a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x820(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1090 <ftpd_popen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    $0xd3,%edi
lea    0xe20(%rip),%rsi
call   10b0 <lreply@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%eax
je     12b3 <statfilecmd+0x113>
cmpl   $0xa,-0x14(%rbp)
jne    129c <statfilecmd+0xfc>
mov    0x2db5(%rip),%rax
mov    (%rax),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1259 <statfilecmd+0xb9>
mov    $0x1a5,%edi
lea    0xddf(%rip),%rsi
call   10a0 <perror_reply@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftpd_pclose@plt>
mov    $0x1,%edi
call   1060 <dologout@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1288 <statfilecmd+0xe8>
mov    -0x8(%rbp),%rsi
mov    $0x227,%edi
call   10a0 <perror_reply@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ftpd_pclose@plt>
jmp    12cd <statfilecmd+0x12d>
mov    0x2d49(%rip),%rax
mov    (%rax),%rsi
mov    $0xd,%edi
call   1080 <putc@plt>
mov    -0x14(%rbp),%edi
mov    0x2d32(%rip),%rax
mov    (%rax),%rsi
call   1080 <putc@plt>
jmp    11f7 <statfilecmd+0x57>
mov    -0x10(%rbp),%rdi
call   1040 <ftpd_pclose@plt>
mov    $0xd3,%edi
lea    0xd6b(%rip),%rsi
call   1070 <reply@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<statfilecmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
lea    0xe45(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <ftpd_popen@plt>
mov    %rax,%rbx
lea    0xe2b(%rip),%rsi
mov    $0xd3,%edi
mov    %r14,%rdx
call   10b0 <lreply@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
mov    0x2de5(%rip),%r12
cmp    (%r12),%eax
jne    1234 <statfilecmd+0x94>
mov    %rbx,%rdi
call   1040 <ftpd_pclose@plt>
lea    0xe1b(%rip),%rsi
mov    $0xd3,%edi
call   1070 <reply@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    0x2d9b(%rip),%r13
lea    0xddc(%rip),%r15
jmp    126b <statfilecmd+0xcb>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%rsi
mov    %ebp,%edi
call   1080 <putc@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
je     1209 <statfilecmd+0x69>
cmp    $0xa,%ebp
jne    1250 <statfilecmd+0xb0>
mov    0x0(%r13),%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     129d <statfilecmd+0xfd>
mov    $0x1a5,%edi
mov    %r15,%rsi
call   10a0 <perror_reply@plt>
mov    %rbx,%rdi
call   1040 <ftpd_pclose@plt>
mov    $0x1,%edi
call   1060 <dologout@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12ba <statfilecmd+0x11a>
mov    0x0(%r13),%rsi
mov    $0xd,%edi
call   1080 <putc@plt>
jmp    1250 <statfilecmd+0xb0>
mov    $0x227,%edi
mov    %r14,%rsi
call   10a0 <perror_reply@plt>
mov    %rbx,%rdi
call   1040 <ftpd_pclose@plt>
jmp    1222 <statfilecmd+0x82>

LLVM IR (-O0):
@.str = [16 x i8] c"/bin/ls -lgA %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"status of %s:\00"
@EOF = global i32 0
@stdout = global i32* null
@.str.3 = [19 x i8] c"control connection\00"
@.str.4 = [14 x i8] c"End of Status\00"
define void @statfilecmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [2048 x i8]
store i8* %0, i8** %2
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = call i32* @ftpd_popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i8*, i8** %2
%12 = call i32 @lreply(i32 211, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %42, %1
%14 = load i32*, i32** %3
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %4
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %46
18: ; preds = %13
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = load i32*, i32** @stdout
%23 = call i64 @ferror(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i32 @perror_reply(i32 421, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32*, i32** %3
%28 = call i32 @ftpd_pclose(i32* %27)
%29 = call i32 @dologout(i32 1)
br label %30
30: ; preds = %25, %21
%31 = load i32*, i32** %3
%32 = call i64 @ferror(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8*, i8** %2
%36 = call i32 @perror_reply(i32 551, i8* %35)
%37 = load i32*, i32** %3
%38 = call i32 @ftpd_pclose(i32* %37)
br label %50
39: ; preds = %30
%40 = load i32*, i32** @stdout
%41 = call i32 @putc(i32 13, i32* %40)
br label %42
42: ; preds = %39, %18
%43 = load i32, i32* %4
%44 = load i32*, i32** @stdout
%45 = call i32 @putc(i32 %43, i32* %44)
br label %13
46: ; preds = %13
%47 = load i32*, i32** %3
%48 = call i32 @ftpd_pclose(i32* %47)
%49 = call i32 @reply(i32 211, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %46, %34
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/bin/ls -lgA %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"status of %s:\00"
@EOF = global i32 0
@stdout = global i32* null
@.str.3 = [19 x i8] c"control connection\00"
@.str.4 = [14 x i8] c"End of Status\00"
define void @statfilecmd(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 2048, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @ftpd_popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @lreply(i32 211, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%7 = call i32 @getc(i32* %5)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %36, label %10
10: ; preds = %1, %30
%11 = phi i32 [ %33, %30 ], [ %7, %1 ]
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32*, i32** @stdout
%15 = call i64 @ferror(i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = call i32 @perror_reply(i32 421, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @ftpd_pclose(i32* %5)
%20 = call i32 @dologout(i32 1)
br label %21
21: ; preds = %17, %13
%22 = call i64 @ferror(i32* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i32 @perror_reply(i32 551, i8* %0)
%26 = call i32 @ftpd_pclose(i32* %5)
br label %39
27: ; preds = %21
%28 = load i32*, i32** @stdout
%29 = call i32 @putc(i32 13, i32* %28)
br label %30
30: ; preds = %27, %10
%31 = load i32*, i32** @stdout
%32 = call i32 @putc(i32 %11, i32* %31)
%33 = call i32 @getc(i32* %5)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %10
36: ; preds = %30, %1
%37 = call i32 @ftpd_pclose(i32* %5)
%38 = call i32 @reply(i32 211, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %36, %24
ret void
}