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

/* 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 /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
void create1(const char *d, const char *f, const char *in) {
  int fd;
  char n[512];
  sleep(1);
  sprintf(n, "%s/%s", d, f);
  fd = creat(n, 0666);
  if (fd < 0) {
    fprintf(stderr, "test-lab-3-b: create(%s): %s\n", n, strerror(errno));
    exit(1);
  }
  if (write(fd, in, strlen(in)) != strlen(in)) {
    fprintf(stderr, "test-lab-3-b: write(%s): %s\n", n, strerror(errno));
    exit(1);
  }
  if (close(fd) != 0) {
    fprintf(stderr, "test-lab-3-b: close(%s): %s\n", n, strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<create1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe39(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    $0x1b6,%esi
call   1070 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123b <create1+0xab>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rdx
mov    %rax,%rcx
lea    0xdda(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x244(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    -0x240(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x238(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x238(%rbp),%rax
cmp    %rcx,%rax
je     12e1 <create1+0x151>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x254(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x254(%rbp),%edi
mov    -0x250(%rbp),%rdx
mov    %rax,%rcx
lea    0xd52(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     1344 <create1+0x1b4>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x264(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x264(%rbp),%edi
mov    -0x260(%rbp),%rdx
mov    %rax,%rcx
lea    0xd0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbp
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xe47(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1080 <sprintf@plt>
mov    %r15,%rdi
mov    $0x1b6,%esi
call   1070 <creat@plt>
test   %eax,%eax
js     121e <create1+0x8e>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jne    123e <create1+0xae>
mov    %ebp,%edi
call   1050 <close@plt>
test   %rax,%rax
jne    125e <create1+0xce>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dbb(%rip),%rax
mov    (%rax),%ebx
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdca(%rip),%rsi
jmp    127c <create1+0xec>
mov    0x2d9b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc8(%rip),%rsi
jmp    127c <create1+0xec>
mov    0x2d7b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc5(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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