#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 mode_t;

/* Variables and functions */
int /*<<< orphan*/ O_CREAT;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char const *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int utime(char const *, int /*<<< orphan*/ *);
int touch(const char *filename) {
  int fd;
  mode_t mode;
  mode = S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH;
  fd = open(filename, O_CREAT, mode);
  if (fd < 0) {
    fprintf(stderr, "error: failed to create file\n");
    return (errno);
  }
  close(fd);
  return (utime(filename, NULL));
}


x86 assembly (clang, -O0):
<touch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    0x2e5c(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e69(%rip),%rcx
or     (%rcx),%eax
mov    0x2e18(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cd <touch+0x8d>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <touch+0xa5>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <utime@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touch>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e56(%rip),%rax
or     (%rax),%edx
mov    %rdi,%rbx
mov    0x2e72(%rip),%rax
or     (%rax),%edx
mov    0x2e71(%rip),%rax
or     (%rax),%edx
mov    0x2e20(%rip),%rax
or     (%rax),%edx
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     119e <touch+0x5e>
mov    %eax,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
xor    %esi,%esi
pop    %rbx
jmp    1030 <utime@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"error: failed to create file\0A\00"
@errno = global i32 0
define i32 @touch(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IROTH
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IWGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWOTH
%16 = or i32 %14, %15
store i32 %16, i32* %5
%17 = load i8*, i8** %3
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* %5
%20 = call i32 @open(i8* %17, i32 %18, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @errno
store i32 %26, i32* %2
br label %32
27: ; preds = %1
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
%30 = load i8*, i8** %3
%31 = call i32 @utime(i8* %30, i32* null)
store i32 %31, i32* %2
br label %32
32: ; preds = %27, %23
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"error: failed to create file\0A\00"
@errno = global i32 0
define i32 @touch(i8* nocapture %0) {
%2 = load i32, i32* @S_IRUSR
%3 = load i32, i32* @S_IRGRP
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IROTH
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IWGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWOTH
%12 = or i32 %10, %11
%13 = load i32, i32* @O_CREAT
%14 = tail call i32 @open(i8* %0, i32 %13, i32 %12)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @errno
br label %23
20: ; preds = %1
%21 = tail call i32 @close(i32 %14)
%22 = tail call i32 @utime(i8* %0, i32* null)
br label %23
23: ; preds = %20, %16
%24 = phi i32 [ %19, %16 ], [ %22, %20 ]
ret i32 %24
}