#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*/);
scalar_t__ chdir(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ lstat(char *, struct stat *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *fn, buf[512], *n;
  struct stat st;
  if (argc > 1 && chdir(argv[1]) < 0) {
    fprintf(stderr, "getfiles: %s: %s.\n", argv[1], strerror(errno));
    return 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    120e <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    120e <main+0x8e>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x238(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rdx
mov    %rax,%rcx
lea    0xe03(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <main+0x16b>
jmp    1213 <main+0x93>
lea    -0x220(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x23d(%rbp)
je     1264 <main+0xe4>
lea    -0x220(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x23d(%rbp)
mov    -0x23d(%rbp),%al
test   $0x1,%al
jne    1277 <main+0xf7>
jmp    12e4 <main+0x164>
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     12a8 <main+0x128>
mov    -0x228(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%eax
jne    12df <main+0x15f>
mov    -0x230(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     12df <main+0x15f>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
jmp    1213 <main+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
cmp    $0x2,%edi
jl     11a9 <main+0x29>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
js     124f <main+0xcf>
mov    0x2e38(%rip),%r12
mov    (%r12),%edx
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1284 <main+0x104>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
jmp    11fa <main+0x7a>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1284 <main+0x104>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1284 <main+0x104>
mov    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1228 <main+0xa8>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <lstat@plt>
test   %eax,%eax
jne    11e0 <main+0x60>
mov    0x8(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     11e0 <main+0x60>
mov    %rbp,%rdi
call   1030 <puts@plt>
jmp    11e0 <main+0x60>
mov    0x2d82(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8f(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"getfiles: %s: %s.\0A\00"
@errno = global i32 0
@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 %26
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @chdir(i8* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
store i32 1, i32* %3
br label %59
26: ; preds = %12, %2
br label %27
27: ; preds = %57, %26
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i32* @fgets(i8* %28, i32 512, i32 %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%34 = call i8* @strchr(i8* %33, i8 signext 32)
store i8* %34, i8** %6
%35 = icmp ne i8* %34, null
br label %36
36: ; preds = %32, %27
%37 = phi i1 [ false, %27 ], [ %35, %32 ]
br i1 %37, label %38, label %58
38: ; preds = %36
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %6
%41 = call i8* @strchr(i8* %40, i8 signext 10)
store i8* %41, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load i8*, i8** %8
store i8 0, i8* %44
br label %45
45: ; preds = %43, %38
%46 = load i8*, i8** %6
%47 = call i32 @lstat(i8* %46, %struct.stat* %9)
%48 = icmp ne i32 %47, 0
br i1 %48, label %57, label %49
49: ; preds = %45
%50 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i64 @S_ISREG(i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i8*, i8** %6
%56 = call i32 @puts(i8* %55)
br label %57
57: ; preds = %54, %49, %45
br label %27
58: ; preds = %36
store i32 0, i32* %3
br label %59
59: ; preds = %58, %18
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"getfiles: %s: %s.\0A\00"
@errno = global i32 0
@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 %19
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @chdir(i8* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17)
br label %46
19: ; preds = %8, %2
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %5, i32 512, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %46, label %23
23: ; preds = %19
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %25
25: ; preds = %23, %42
%26 = call i8* @strchr(i8* %5, i8 signext 32)
%27 = icmp eq i8* %26, null
br i1 %27, label %46, label %28
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = call i8* @strchr(i8* %29, i8 signext 10)
%31 = icmp eq i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %28
store i8 0, i8* %30
br label %33
33: ; preds = %32, %28
%34 = call i32 @lstat(i8* %29, %struct.stat* %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* %24
%38 = call i64 @S_ISREG(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 @puts(i8* %29)
br label %42
42: ; preds = %40, %36, %33
%43 = load i32, i32* @stdin
%44 = call i32* @fgets(i8* %5, i32 512, i32 %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %25
46: ; preds = %42, %25, %19, %13
%47 = phi i32 [ 1, %13 ], [ 0, %19 ], [ 0, %25 ], [ 0, %42 ]
ret i32 %47
}