#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*/ open_path;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void create_files(int count) {
  int fd = 0;
  char open_path[64];
  int i;
  for (i = 0; i < count; i++) {
    snprintf(open_path, sizeof(open_path), "/tmp/tmpdir/file%d", i);
    fd = open(open_path, O_RDWR | O_CREAT);
    if (fd == -1) {
      fprintf(stderr, "Unable to create file %s: %s\n", open_path,
              strerror(errno));
      exit(1);
    }
    close(fd);
  }
}


x86 assembly (clang, -O0):
<create_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121d <create_files+0xbd>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    $0x40,%esi
lea    0xe68(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1207 <create_files+0xa7>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1179 <create_files+0x19>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
jle    11c6 <create_files+0x66>
mov    %edi,%r15d
xor    %ebp,%ebp
lea    0xe82(%rip),%r14
mov    %rsp,%rbx
mov    0x2e58(%rip),%r12
mov    0x2e69(%rip),%r13
nop
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d5 <create_files+0x75>
mov    %eax,%edi
call   1040 <close@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1190 <create_files+0x30>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df4(%rip),%rax
mov    (%rax),%ebx
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe20(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/tmpdir/file%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unable to create file %s: %s\0A\00"
@errno = global i32 0
define void @create_files(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %5
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %34
10: ; preds = %6
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %5
%13 = call i32 @snprintf(i8* %11, i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %14, i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %10
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %28
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %6
34: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/tmpdir/file%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unable to create file %s: %s\0A\00"
@errno = global i32 0
define void @create_files(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %23
5: ; preds = %1, %19
%6 = phi i32 [ %21, %19 ], [ 0, %1 ]
%7 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = call i32 @open(i8* %3, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %5
%20 = call i32 @close(i32 %11)
%21 = add nuw nsw i32 %6, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %5
23: ; preds = %19, %1
ret void
}