#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 /*<<< orphan*/ parse_file(char const *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int is_allowed_cmd(const char *path_to_file, char *str) {
  char command[256];
  sprintf(command, "%s", str);
  int len = strlen(command);
  if (command[len - 1] != '\n') {
    command[len] = '\n';
    command[len + 1] = '\0';
  }
  if (!parse_file(path_to_file, command))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_allowed_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xeab(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11aa <is_allowed_cmd+0x7a>
movslq -0x124(%rbp),%rax
movb   $0xa,-0x120(%rbp,%rax,1)
0a
mov    -0x124(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1040 <parse_file@plt>
cmp    $0x0,%eax
jne    11cf <is_allowed_cmd+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <is_allowed_cmd+0xa6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_allowed_cmd>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     115f <is_allowed_cmd+0x2f>
movw   $0xa,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <parse_file@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
mov    %ecx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @is_allowed_cmd(i8* %0, i8* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %1)
%6 = call i32 @strlen(i8* %4)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %13
store i8 10, i8* %14
%15 = add nsw i32 %6, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %12, %2
%19 = call i32 @parse_file(i8* %0, i8* %4)
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i32
ret i32 %21
}