#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *getUserInput(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, char *, char *);
scalar_t__ strncmp(char *, char *, int);
void getCommand(char **command, char **filename) {
  char *message;
  int n;
  for (;;) {
    message = getUserInput("Enter GET/SEND followed by the desired filename: ");
    if ((n = sscanf(message, "%s %s", *command, *filename)) == EOF) {
      perror("sscanf");
      exit(EXIT_FAILURE);
    }
    free(message);
    if (n == 2) {
      if (strncmp(*command, "GET", 3) == 0 ||
          (strncmp(*command, "SEND", 4) == 0 && access(*filename, R_OK) == 0)) {
        break;
      }
    }
    printf("Invalid input\n");
  }
}


x86 assembly (clang, -O0):
<getCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe69(%rip),%rdi
call   1060 <getUserInput@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe79(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
jne    11ea <getCommand+0x6a>
lea    0xe61(%rip),%rdi
call   1090 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x2,-0x1c(%rbp)
jne    126a <getCommand+0xea>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe34(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1260 <getCommand+0xe0>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe16(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1265 <getCommand+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
jne    1265 <getCommand+0xe5>
jmp    127b <getCommand+0xfb>
jmp    126a <getCommand+0xea>
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
jmp    1190 <getCommand+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe68(%rip),%rdi
call   1060 <getUserInput@plt>
mov    %rax,%r15
mov    (%rbx),%rdx
mov    (%r14),%rcx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
call   1070 <sscanf@plt>
mov    %eax,%r13d
mov    0x2e29(%rip),%rax
cmp    (%rax),%r13d
je     1280 <getCommand+0x100>
lea    0xe31(%rip),%rbp
lea    0xe5c(%rip),%r12
jmp    1217 <getCommand+0x97>
nopl   0x0(%rax,%rax,1)
lea    0xe61(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1060 <getUserInput@plt>
mov    %rax,%r15
mov    (%rbx),%rdx
mov    (%r14),%rcx
mov    %rax,%rdi
mov    %r12,%rsi
call   1070 <sscanf@plt>
mov    %eax,%r13d
mov    0x2dd6(%rip),%rax
cmp    (%rax),%r13d
je     1280 <getCommand+0x100>
mov    %r15,%rdi
call   1030 <free@plt>
cmp    $0x2,%r13d
jne    11e0 <getCommand+0x60>
mov    (%rbx),%rdi
lea    0xe10(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1271 <getCommand+0xf1>
mov    (%rbx),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11e0 <getCommand+0x60>
mov    (%r14),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
test   %rax,%rax
jne    11e0 <getCommand+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"Enter GET/SEND followed by the desired filename: \00"
@.str.1 = [6 x i8] c"%s %s\00"
@EOF = global i32 0
@.str.2 = [7 x i8] c"sscanf\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [5 x i8] c"SEND\00"
@R_OK = global i32 0
@.str.5 = [15 x i8] c"Invalid input\0A\00"
define void @getCommand(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
br label %7
7: ; preds = %44, %2
%8 = call i8* @getUserInput(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
%14 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %7
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %44
26: ; preds = %21
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %42, label %31
31: ; preds = %26
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i8**, i8*** %4
%38 = load i8*, i8** %37
%39 = load i32, i32* @R_OK
%40 = call i64 @access(i8* %38, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36, %26
br label %46
43: ; preds = %36, %31
br label %44
44: ; preds = %43, %21
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %7
46: ; preds = %42
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"Enter GET/SEND followed by the desired filename: \00"
@.str.1 = [6 x i8] c"%s %s\00"
@EOF = global i32 0
@.str.2 = [7 x i8] c"sscanf\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [5 x i8] c"SEND\00"
@R_OK = global i32 0
@str = [14 x i8] c"Invalid input\00"
define void @getCommand(i8** nocapture %0, i8** nocapture %1) {
%3 = tail call i8* @getUserInput(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%4 = load i8*, i8** %0
%5 = load i8*, i8** %1
%6 = tail call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %5)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %31, %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2, %31
%14 = phi i32 [ %36, %31 ], [ %6, %2 ]
%15 = phi i8* [ %33, %31 ], [ %3, %2 ]
%16 = tail call i32 @free(i8* %15)
%17 = icmp eq i32 %14, 2
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = load i8*, i8** %0
%20 = tail call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %39, label %22
22: ; preds = %18
%23 = load i8*, i8** %0
%24 = tail call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %1
%28 = load i32, i32* @R_OK
%29 = tail call i64 @access(i8* %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %22, %26, %13
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%33 = tail call i8* @getUserInput(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%34 = load i8*, i8** %0
%35 = load i8*, i8** %1
%36 = tail call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %9, label %13
39: ; preds = %18, %26
ret void
}