#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 */
int EINTR;
int O_CLOEXEC;
int O_CREAT;
int O_NOCTTY;
int O_WRONLY;
scalar_t__ close(int);
int errno;
int /*<<< orphan*/ mkdir(char *, int);
int open(char const *, int, int);
int touch(const char *path) {
  int fd;
  mkdir("/run/systemd", 0755);
  mkdir("/run/systemd/readahead", 0755);
  fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC | O_NOCTTY, 0666);
  if (fd < 0)
    return -errno;
  for (;;) {
    if (close(fd) >= 0)
      break;
    if (errno != EINTR)
      return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<touch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xeb9(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
mov    0x2e54(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b0 <touch+0x80>
xor    %eax,%eax
mov    0x2e2a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <touch+0xd3>
jmp    11b5 <touch+0x85>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jl     11cc <touch+0x9c>
jmp    11fc <touch+0xcc>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
je     11f7 <touch+0xc7>
xor    %eax,%eax
mov    0x2de3(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <touch+0xd3>
jmp    11b5 <touch+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touch>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xebd(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    0x2e57(%rip),%rax
mov    0x2e90(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11b8 <touch+0x88>
mov    %eax,%ebx
mov    0x2e38(%rip),%r14
mov    0x2e29(%rip),%r15
nop
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jns    11c5 <touch+0x95>
mov    (%r14),%eax
cmp    (%r15),%eax
je     11a0 <touch+0x70>
neg    %eax
jmp    11c7 <touch+0x97>
mov    0x2e11(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    11c7 <touch+0x97>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/run/systemd\00"
@.str.1 = [23 x i8] c"/run/systemd/readahead\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@O_NOCTTY = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @touch(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @mkdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 493)
%6 = call i32 @mkdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 493)
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CLOEXEC
%12 = or i32 %10, %11
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %7, i32 %14, i32 438)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i32, i32* @errno
%20 = sub nsw i32 0, %19
store i32 %20, i32* %2
br label %36
21: ; preds = %1
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %4
%24 = call i64 @close(i32 %23)
%25 = icmp sge i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %35
27: ; preds = %22
%28 = load i32, i32* @errno
%29 = load i32, i32* @EINTR
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @errno
%33 = sub nsw i32 0, %32
store i32 %33, i32* %2
br label %36
34: ; preds = %27
br label %22
35: ; preds = %26
store i32 0, i32* %2
br label %36
36: ; preds = %35, %31, %18
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [13 x i8] c"/run/systemd\00"
@.str.1 = [23 x i8] c"/run/systemd/readahead\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@O_NOCTTY = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @touch(i8* nocapture %0) {
%2 = tail call i32 @mkdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 493)
%3 = tail call i32 @mkdir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 493)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_CLOEXEC
%8 = or i32 %6, %7
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %0, i32 %10, i32 438)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = sub nsw i32 0, %14
br label %25
16: ; preds = %1, %19
%17 = tail call i64 @close(i32 %11)
%18 = icmp sgt i64 %17, -1
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = load i32, i32* @EINTR
%22 = icmp eq i32 %20, %21
br i1 %22, label %16, label %23
23: ; preds = %19
%24 = sub nsw i32 0, %20
br label %25
25: ; preds = %16, %23, %13
%26 = phi i32 [ %15, %13 ], [ %24, %23 ], [ 0, %16 ]
ret i32 %26
}