#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 dummy;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, int, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stdout, "*** ERROR: insufficient parameters ... \n\n");
    fprintf(stdout, "USAGE: %s <dir_name> <num_files>\n", argv[0]);
    fprintf(stdout, "\n");
    return -1;
  }
  struct stat statbuf;
  int num_files = atoi(argv[2]);
  char hostname[64] = {0};
  if (gethostname(hostname, sizeof(hostname)) < 0) {
    printf("ERROR during gethostname(): %s", strerror(errno));
    return -1;
  }
  int pid = (int)0;
  printf("Lookup %d files from test_%d ... \n", num_files, pid);
  int i = 0;
  for (i = 0; i < num_files; i++) {
    char path[512] = {0};
    snprintf(path, sizeof(path), "%s/%s_p%d_f%d", argv[1], hostname, pid, i);
    if (stat(path, &statbuf) < 0) {
      printf("ERR_stat(%s): %s\n", path, strerror(errno));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11fb <main+0x7b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133c <main+0x1bc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   1090 <gethostname@plt>
cmp    $0x0,%rax
jge    125e <main+0xde>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133c <main+0x1bc>
movl   $0x0,-0x64(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x64(%rbp),%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1335 <main+0x1b5>
lea    -0x270(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    -0x270(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    -0x60(%rbp),%r8
mov    -0x64(%rbp),%r9d
mov    -0x68(%rbp),%eax
mov    $0x200,%esi
lea    0xdc2(%rip),%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
lea    -0x270(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jge    1322 <main+0x1a2>
lea    -0x270(%rbp),%rax
mov    %rax,-0x278(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x278(%rbp),%rsi
mov    %rax,%rdx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1327 <main+0x1a7>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1287 <main+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x258,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1282 <main+0x102>
mov    0x10(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
call   1090 <gethostname@plt>
test   %rax,%rax
js     12c3 <main+0x143>
lea    0xe8d(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    12eb <main+0x16b>
lea    0x50(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
xor    %r15d,%r15d
jmp    121d <main+0x9d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    %r15d,%ebp
je     12e9 <main+0x169>
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x8(%r14),%rcx
mov    %r15d,(%rsp)
mov    %rbx,%rdi
mov    $0x200,%esi
lea    0xe4b(%rip),%rdx
mov    %r12,%r8
xor    %r9d,%r9d
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <stat@plt>
test   %rax,%rax
jns    1210 <main+0x90>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1210 <main+0x90>
mov    0x2d4f(%rip),%rbx
mov    (%rbx),%edi
lea    0xd6e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r14),%rdx
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd73(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    12eb <main+0x16b>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd74(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
jmp    12eb <main+0x16b>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stdout = global i32 0
@.str = [42 x i8] c"*** ERROR: insufficient parameters ... \0A\0A\00"
@.str.1 = [34 x i8] c"USAGE: %s <dir_name> <num_files>\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [31 x i8] c"ERROR during gethostname(): %s\00"
@errno = global i32 0
@.str.4 = [35 x i8] c"Lookup %d files from test_%d ... \0A\00"
@.str.5 = [14 x i8] c"%s/%s_p%d_f%d\00"
@.str.6 = [18 x i8] c"ERR_stat(%s): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stdout
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = bitcast [64 x i8]* %8 to i8*
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%31 = call i64 @gethostname(i8* %30, i32 64)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %35)
store i32 -1, i32* %3
br label %68
37: ; preds = %24
store i32 0, i32* %9
%38 = load i32, i32* %7
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %39)
store i32 0, i32* %10
store i32 0, i32* %10
br label %41
41: ; preds = %64, %37
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %67
45: ; preds = %41
%46 = bitcast [512 x i8]* %11 to i8*
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = call i32 @snprintf(i8* %47, i32 512, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %50, i8* %51, i32 %52, i32 %53)
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%56 = call i64 @stat(i8* %55, %struct.stat* %6)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %45
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %59, i8* %61)
br label %63
63: ; preds = %58, %45
br label %64
64: ; preds = %63
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %41
67: ; preds = %41
store i32 0, i32* %3
br label %68
68: ; preds = %67, %33, %14
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stdout = global i32 0
@.str = [42 x i8] c"*** ERROR: insufficient parameters ... \0A\0A\00"
@.str.1 = [34 x i8] c"USAGE: %s <dir_name> <num_files>\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [31 x i8] c"ERROR during gethostname(): %s\00"
@errno = global i32 0
@.str.4 = [35 x i8] c"Lookup %d files from test_%d ... \0A\00"
@.str.5 = [14 x i8] c"%s/%s_p%d_f%d\00"
@.str.6 = [18 x i8] c"ERR_stat(%s): %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [64 x i8]
%5 = alloca [512 x i8]
%6 = icmp eq i32 %0, 3
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdout
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %48
15: ; preds = %2
%16 = bitcast %struct.stat* %3 to i8*
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%21 = call i64 @gethostname(i8* %20, i32 64)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %46
27: ; preds = %15
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 0)
%29 = icmp sgt i32 %19, 0
br i1 %29, label %30, label %46
30: ; preds = %27
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%32 = getelementptr inbounds i8*, i8** %1, i64 1
br label %33
33: ; preds = %30, %43
%34 = phi i32 [ 0, %30 ], [ %44, %43 ]
%35 = load i8*, i8** %32
%36 = call i32 @snprintf(i8* %31, i32 512, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %35, i8* %20, i32 0, i32 %34)
%37 = call i64 @stat(i8* %31, %struct.stat* %3)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %31, i8* %41)
br label %43
43: ; preds = %39, %33
%44 = add nuw nsw i32 %34, 1
%45 = icmp eq i32 %44, %19
br i1 %45, label %46, label %33
46: ; preds = %43, %27, %23
%47 = phi i32 [ -1, %23 ], [ 0, %27 ], [ 0, %43 ]
br label %48
48: ; preds = %46, %7
%49 = phi i32 [ -1, %7 ], [ %47, %46 ]
ret i32 %49
}