#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 atoi(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ perror_msg_and_die(char *);
int ftpcmd(char *s1, char *s2, FILE *fp, char *buf) {
  char *p;
  if (s1) {
    if (!s2)
      s2 = "";
    fprintf(fp, "%s%s\n", s1, s2);
    fflush(fp);
  }
  do {
    p = fgets(buf, 510, fp);
    if (!p)
      perror_msg_and_die("fgets()");
  } while (!isdigit(buf[0]) || buf[3] != ' ');
  return atoi(buf);
}


x86 assembly (clang, -O0):
<ftpcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ba <ftpcmd+0x5a>
cmpq   $0x0,-0x10(%rbp)
jne    1199 <ftpcmd+0x39>
lea    0xe70(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fflush@plt>
jmp    11bf <ftpcmd+0x5f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1fe,%esi
call   1040 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ec <ftpcmd+0x8c>
lea    0xe1f(%rip),%rdi
call   1060 <perror_msg_and_die@plt>
jmp    11f1 <ftpcmd+0x91>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     121e <ftpcmd+0xbe>
mov    -0x20(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11bf <ftpcmd+0x5f>
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftpcmd>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
test   %rdi,%rdi
je     1198 <ftpcmd+0x38>
mov    %rdi,%rdx
test   %rsi,%rsi
lea    0xe88(%rip),%rcx
cmovne %rsi,%rcx
lea    0xe78(%rip),%rsi
mov    %r14,%rdi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1070 <fflush@plt>
lea    0xe67(%rip),%r15
nop
mov    %rbx,%rdi
mov    $0x1fe,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11bd <ftpcmd+0x5d>
mov    %r15,%rdi
call   1060 <perror_msg_and_die@plt>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11a0 <ftpcmd+0x40>
cmpb   $0x20,0x3(%rbx)
jne    11a0 <ftpcmd+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <atoi@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%s%s\0A\00"
@.str.2 = [8 x i8] c"fgets()\00"
define i32 @ftpcmd(i8* %0, i8* %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %23
12: ; preds = %4
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %16
16: ; preds = %15, %12
%17 = load i32*, i32** %7
%18 = load i8*, i8** %5
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i32*, i32** %7
%22 = call i32 @fflush(i32* %21)
br label %23
23: ; preds = %16, %4
br label %24
24: ; preds = %45, %23
%25 = load i8*, i8** %8
%26 = load i32*, i32** %7
%27 = call i8* @fgets(i8* %25, i32 510, i32* %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %24
%31 = call i32 @perror_msg_and_die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
br label %33
33: ; preds = %32
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = call i32 @isdigit(i8 signext %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 3
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 32
br label %45
45: ; preds = %39, %33
%46 = phi i1 [ true, %33 ], [ %44, %39 ]
br i1 %46, label %24, label %47
47: ; preds = %45
%48 = load i8*, i8** %8
%49 = call i32 @atoi(i8* %48)
ret i32 %49
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"%s%s\0A\00"
@.str.2 = [8 x i8] c"fgets()\00"
define i32 @ftpcmd(i8* %0, i8* %1, i32* nocapture %2, i8* %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = icmp eq i8* %1, null
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%9 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %8)
%10 = tail call i32 @fflush(i32* %2)
br label %11
11: ; preds = %6, %4
%12 = getelementptr inbounds i8, i8* %3, i64 3
br label %13
13: ; preds = %25, %11
%14 = tail call i8* @fgets(i8* %3, i32 510, i32* %2)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @perror_msg_and_die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %13, %16
%19 = load i8, i8* %3
%20 = tail call i32 @isdigit(i8 signext %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8, i8* %12
%24 = icmp eq i8 %23, 32
br i1 %24, label %26, label %25
25: ; preds = %22, %18
br label %13
26: ; preds = %22
%27 = tail call i32 @atoi(i8* %3)
ret i32 %27
}