#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 */
typedef int /*<<< orphan*/ i;

/* Variables and functions */
scalar_t__ close(int);
int creat(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, int *, int);
void createn(const char *d, const char *prefix, int nf) {
  int fd, i;
  char n[512];
  sleep(1);
  for (i = 0; i < nf; i++) {
    sprintf(n, "%s/%s-%d", d, prefix, i);
    fd = creat(n, 0666);
    if (fd < 0) {
      fprintf(stderr, "test-lab-3-c: create(%s): %s\n", n, strerror(errno));
      exit(1);
    }
    if (write(fd, &i, sizeof(i)) != sizeof(i)) {
      fprintf(stderr, "test-lab-3-c: write(%s): %s\n", n, strerror(errno));
      exit(1);
    }
    if (close(fd) != 0) {
      fprintf(stderr, "test-lab-3-c: close(%s): %s\n", n, strerror(errno));
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<createn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1325 <createn+0x1a5>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe33(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1241 <createn+0xc1>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cltq
cmp    $0x4,%rax
je     12af <createn+0x12f>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rdx
mov    %rax,%rcx
lea    0xd87(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     1312 <createn+0x192>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rdx
mov    %rax,%rcx
lea    0xd41(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1317 <createn+0x197>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a7 <createn+0x27>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%edi
call   10a0 <sleep@plt>
movl   $0x0,0xc(%rsp)
test   %r13d,%r13d
jle    121b <createn+0x9b>
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe36(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1060 <creat@plt>
test   %eax,%eax
js     122d <createn+0xad>
mov    %eax,%r12d
mov    %eax,%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    124d <createn+0xcd>
mov    %r12d,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    126d <createn+0xed>
add    $0x1,%ebp
mov    %ebp,0xc(%rsp)
cmp    %ebp,%r13d
jne    11c0 <createn+0x40>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dac(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdbe(%rip),%rsi
jmp    128b <createn+0x10b>
mov    0x2d8c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdbc(%rip),%rsi
jmp    128b <createn+0x10b>
mov    0x2d6c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb9(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%s/%s-%d\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"test-lab-3-c: create(%s): %s\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"test-lab-3-c: write(%s): %s\0A\00"
@.str.3 = [29 x i8] c"test-lab-3-c: close(%s): %s\0A\00"
define void @createn(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i32 @sleep(i32 1)
store i32 0, i32* %8
br label %11
11: ; preds = %56, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %59
15: ; preds = %11
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i32 %19)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%22 = call i32 @creat(i8* %21, i32 438)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %15
%33 = load i32, i32* %7
%34 = call i32 @write(i32 %33, i32* %8, i32 4)
%35 = sext i32 %34 to i64
%36 = icmp ne i64 %35, 4
br i1 %36, label %37, label %44
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = load i32, i32* %7
%46 = call i64 @close(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %44
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %11
59: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s/%s-%d\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"test-lab-3-c: create(%s): %s\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"test-lab-3-c: write(%s): %s\0A\00"
@.str.3 = [29 x i8] c"test-lab-3-c: close(%s): %s\0A\00"
define void @createn(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @sleep(i32 1)
store i32 0, i32* %4
%9 = icmp sgt i32 %2, 0
br i1 %9, label %12, label %42
10: ; preds = %32
store i32 %35, i32* %4
%11 = icmp eq i32 %35, %2
br i1 %11, label %42, label %12
12: ; preds = %3, %10
%13 = phi i32 [ %35, %10 ], [ 0, %3 ]
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %13)
%15 = call i32 @creat(i8* %7, i32 438)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = call i32 @write(i32 %15, i32* %4, i32 4)
%25 = icmp eq i32 %24, 4
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = call i64 @close(i32 %15)
%34 = icmp eq i64 %33, 0
%35 = add nuw nsw i32 %13, 1
br i1 %34, label %10, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %10, %3
ret void
}