#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);
  if ((fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC | O_NOCTTY, 0666)) < 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)
cmp    $0x0,%eax
jge    11af <touch+0x7f>
xor    %eax,%eax
mov    0x2e2b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <touch+0xd6>
jmp    11b4 <touch+0x84>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jl     11cb <touch+0x9b>
jmp    11ff <touch+0xcf>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
mov    0x2deb(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     11fa <touch+0xca>
xor    %eax,%eax
mov    0x2de0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <touch+0xd6>
jmp    11b4 <touch+0x84>
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     11ba <touch+0x8a>
mov    %eax,%ebx
mov    0x2e38(%rip),%r14
mov    0x2e29(%rip),%r15
nop
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jns    11c7 <touch+0x97>
mov    (%r14),%eax
mov    (%r15),%ecx
add    %eax,%ecx
je     11a0 <touch+0x70>
neg    %eax
jmp    11c9 <touch+0x99>
mov    0x2e0f(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    11c9 <touch+0x99>
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 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i32, i32* @errno
%19 = sub nsw i32 0, %18
store i32 %19, i32* %2
br label %36
20: ; preds = %1
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %4
%23 = call i64 @close(i32 %22)
%24 = icmp sge i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %35
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = load i32, i32* @EINTR
%29 = sub nsw i32 0, %28
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = sub nsw i32 0, %32
store i32 %33, i32* %2
br label %36
34: ; preds = %26
br label %21
35: ; preds = %25
store i32 0, i32* %2
br label %36
36: ; preds = %35, %31, %17
%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 %26
16: ; preds = %1, %19
%17 = tail call i64 @close(i32 %11)
%18 = icmp sgt i64 %17, -1
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = load i32, i32* @EINTR
%22 = sub nsw i32 0, %21
%23 = icmp eq i32 %20, %22
br i1 %23, label %16, label %24
24: ; preds = %19
%25 = sub nsw i32 0, %20
br label %26
26: ; preds = %16, %24, %13
%27 = phi i32 [ %15, %13 ], [ %25, %24 ], [ 0, %16 ]
ret i32 %27
}