#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 */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int hist(char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
char *realpath(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int rc = 0;
  struct stat st;
  for (int i = 1; i < argc; i++) {
    char *path = argv[i];
    rc = lstat(path, &st);
    if (rc == -1) {
      fprintf(stderr, "lstat() error %s\n", strerror(errno));
      continue;
    }
    if (!S_ISREG(st.st_mode)) {
      continue;
    }
    char *abs_path = realpath(path, NULL);
    if (abs_path == NULL) {
      fprintf(stderr, "realpath() error %s\n", strerror(errno));
      continue;
    }
    printf("%s\n", abs_path);
    free(abs_path);
    rc = hist(path);
    if (rc) {
      printf("-- couldn't hist() file\n");
    }
    printf("\n");
  }
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12c9 <main+0x149>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120b <main+0x8b>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12bb <main+0x13b>
mov    -0x18(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1221 <main+0xa1>
jmp    12bb <main+0x13b>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <realpath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    126e <main+0xee>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12bb <main+0x13b>
mov    -0x30(%rbp),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1090 <hist@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12ad <main+0x12d>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a4 <main+0x24>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
xor    %ebp,%ebp
cmp    $0x2,%edi
jl     1299 <main+0x109>
mov    %edi,%r14d
mov    $0x1,%r15d
lea    0x8(%rsp),%rbx
jmp    11fa <main+0x6a>
xchg   %ax,%ax
mov    0x2e19(%rip),%rax
mov    (%rax),%ebp
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %ebp,%edi
lea    0xe20(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
add    $0x1,%r15
cmp    %r15,%r14
je     1299 <main+0x109>
mov    0x10(%rsp),%rax
mov    (%rax,%r15,8),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <lstat@plt>
cmp    $0xffffffff,%eax
je     11c0 <main+0x30>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %eax,%eax
je     11ed <main+0x5d>
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <realpath@plt>
test   %rax,%rax
je     126a <main+0xda>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   10a0 <hist@plt>
mov    %eax,%ebp
test   %eax,%eax
je     125e <main+0xce>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11ed <main+0x5d>
mov    0x2d6f(%rip),%rax
mov    (%rax),%r12d
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %r12d,%edi
lea    0xd86(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
jmp    11ed <main+0x5d>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"lstat() error %s\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"realpath() error %s\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [25 x i8] c"-- couldn't hist() file\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %8
br label %11
11: ; preds = %59, %2
%12 = load i32, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %62
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 @lstat(i8* %21, %struct.stat* %7)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %59
30: ; preds = %15
%31 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @S_ISREG(i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %30
br label %59
36: ; preds = %30
%37 = load i8*, i8** %9
%38 = call i8* @realpath(i8* %37, i32* null)
store i8* %38, i8** %10
%39 = load i8*, i8** %10
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %59
46: ; preds = %36
%47 = load i8*, i8** %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %10
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %9
%52 = call i32 @hist(i8* %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %46
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %46
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %41, %35, %25
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %11
62: ; preds = %11
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"lstat() error %s\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"realpath() error %s\0A\00"
@str = [24 x i8] c"-- couldn't hist() file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%8 = zext i32 %0 to i64
br label %11
9: ; preds = %43, %2
%10 = phi i32 [ 0, %2 ], [ %44, %43 ]
ret i32 %10
11: ; preds = %6, %43
%12 = phi i64 [ 1, %6 ], [ %45, %43 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @lstat(i8* %14, %struct.stat* %3)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %43
22: ; preds = %11
%23 = load i32, i32* %7
%24 = tail call i32 @S_ISREG(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %43, label %26
26: ; preds = %22
%27 = tail call i8* @realpath(i8* %14, i32* null)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %43
34: ; preds = %26
%35 = tail call i32 @puts(i8* %27)
%36 = tail call i32 @free(i8* %27)
%37 = tail call i32 @hist(i8* %14)
%38 = icmp eq i32 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %34
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = tail call i32 @putchar(i32 10)
br label %43
43: ; preds = %29, %41, %22, %17
%44 = phi i32 [ -1, %17 ], [ %15, %22 ], [ %15, %29 ], [ %37, %41 ]
%45 = add nuw nsw i64 %12, 1
%46 = icmp eq i64 %45, %8
br i1 %46, label %9, label %11
}