#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ lstat(char *, struct stat *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int main(int argc, char **argv) {
  char *fn, buf[512], *n;
  struct stat st;
  if (argc > 1)
    chdir(argv[1]);
  while (fgets(buf, 512, stdin) != NULL && (fn = strchr(buf, ' ')) != NULL) {
    if ((n = strchr(++fn, '\n')) != NULL)
      *n = '\0';
    if (!lstat(fn, &st) && S_ISREG(st.st_mode))
      puts(fn);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1190 <main+0x30>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
jmp    1195 <main+0x35>
lea    -0x220(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x231(%rbp)
je     11e6 <main+0x86>
lea    -0x220(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x231(%rbp)
mov    -0x231(%rbp),%al
test   $0x1,%al
jne    11f9 <main+0x99>
jmp    1266 <main+0x106>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x18(%rbp)
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x228(%rbp)
cmp    $0x0,%rax
je     122a <main+0xca>
mov    -0x228(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%eax
jne    1261 <main+0x101>
mov    -0x230(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%rax
je     1261 <main+0x101>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
jmp    1195 <main+0x35>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x2,%edi
jl     117c <main+0x1c>
mov    0x8(%rsi),%rdi
call   1040 <chdir@plt>
mov    0x2e65(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     121b <main+0xbb>
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r14
jmp    11c6 <main+0x66>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     121b <main+0xbb>
mov    %r15,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     121b <main+0xbb>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11f4 <main+0x94>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <lstat@plt>
test   %eax,%eax
jne    11b0 <main+0x50>
mov    0x8(%rsp),%edi
call   1080 <S_ISREG@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x50>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [512 x i8]
%8 = alloca i8*
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @chdir(i8* %15)
br label %17
17: ; preds = %12, %2
br label %18
18: ; preds = %48, %17
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %19, i32 512, i32 %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%25 = call i8* @strchr(i8* %24, i8 signext 32)
store i8* %25, i8** %6
%26 = icmp ne i8* %25, null
br label %27
27: ; preds = %23, %18
%28 = phi i1 [ false, %18 ], [ %26, %23 ]
br i1 %28, label %29, label %49
29: ; preds = %27
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = call i8* @strchr(i8* %31, i8 signext 10)
store i8* %32, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i8*, i8** %8
store i8 0, i8* %35
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %6
%38 = call i32 @lstat(i8* %37, %struct.stat* %9)
%39 = icmp ne i32 %38, 0
br i1 %39, label %48, label %40
40: ; preds = %36
%41 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @S_ISREG(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = call i32 @puts(i8* %46)
br label %48
48: ; preds = %45, %40, %36
br label %18
49: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @chdir(i8* %10)
br label %12
12: ; preds = %8, %2
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %5, i32 512, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %39, label %16
16: ; preds = %12
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %18
18: ; preds = %16, %35
%19 = call i8* @strchr(i8* %5, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %39, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %19, i64 1
%23 = call i8* @strchr(i8* %22, i8 signext 10)
%24 = icmp eq i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %21
store i8 0, i8* %23
br label %26
26: ; preds = %25, %21
%27 = call i32 @lstat(i8* %22, %struct.stat* %4)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %17
%31 = call i64 @S_ISREG(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @puts(i8* %22)
br label %35
35: ; preds = %33, %29, %26
%36 = load i32, i32* @stdin
%37 = call i32* @fgets(i8* %5, i32 512, i32 %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %18
39: ; preds = %18, %35, %12
ret i32 0
}