#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 O_CREAT;
int O_EXCL;
int O_WRONLY;
scalar_t__ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int const);
int touch(const char *target) {
  int fd = open(target, O_WRONLY | O_CREAT | O_EXCL, 0755);
  int ret = fd < 0 ? -errno : 0;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("open");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      return ret;
    }
  } while (0);
  ret = close(fd) < 0 ? -errno : 0;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("close");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      return ret;
    }
  } while (0);
  return ret;
}


x86 assembly (clang, -O0):
<touch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a5 <touch+0x55>
xor    %eax,%eax
mov    0x2e2d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x3c(%rbp)
jmp    11af <touch+0x5f>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11af <touch+0x5f>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1220 <touch+0xd0>
lea    0xe34(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1215 <touch+0xc5>
mov    -0x28(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
xor    %edi,%edi
sub    -0x1c(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xdf5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d0 <touch+0x180>
jmp    1225 <touch+0xd5>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    124a <touch+0xfa>
xor    %eax,%eax
mov    0x2d88(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x44(%rbp)
jmp    1254 <touch+0x104>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    1254 <touch+0x104>
mov    -0x44(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12c5 <touch+0x175>
lea    0xd9a(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12ba <touch+0x16a>
mov    -0x38(%rbp),%rdi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
xor    %edi,%edi
sub    -0x2c(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd50(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d0 <touch+0x180>
jmp    12ca <touch+0x17a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e5a(%rip),%rax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
call   1060 <open@plt>
mov    0x2e45(%rip),%r15
xor    %r14d,%r14d
xor    %ebp,%ebp
sub    (%r15),%ebp
mov    %eax,%ebx
sar    $0x1f,%ebx
and    %ebp,%ebx
js     11b6 <touch+0x66>
mov    %eax,%edi
call   1040 <close@plt>
mov    %rax,%rbx
sub    (%r15),%r14d
sar    $0x3f,%rbx
and    %r14d,%ebx
jns    11ec <touch+0x9c>
lea    0xe5a(%rip),%rdi
mov    %r14d,%ebp
jmp    11bd <touch+0x6d>
lea    0xe43(%rip),%rdi
mov    0x2e14(%rip),%r14
mov    (%r14),%esi
call   1030 <fputs@plt>
mov    (%r14),%r14d
neg    %ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe26(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i32 0
@.str = [5 x i8] c"open\00"
@stderr = global i32 0
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [6 x i8] c"close\00"
define i32 @touch(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = load i32, i32* @O_EXCL
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %10, i32 %15, i32 493)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %1
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
br label %23
22: ; preds = %1
br label %23
23: ; preds = %22, %19
%24 = phi i32 [ %21, %19 ], [ 0, %22 ]
store i32 %24, i32* %5
br label %25
25: ; preds = %23
%26 = load i32, i32* %5
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %25
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i32, i32* @stderr
%35 = call i32 @fputs(i8* %33, i32 %34)
%36 = load i32, i32* @stderr
%37 = load i32, i32* %6
%38 = sub nsw i32 0, %37
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %32, %29
%42 = load i32, i32* %5
store i32 %42, i32* %2
br label %75
43: ; preds = %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %4
%46 = call i64 @close(i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* @errno
%50 = sub nsw i32 0, %49
br label %52
51: ; preds = %44
br label %52
52: ; preds = %51, %48
%53 = phi i32 [ %50, %48 ], [ 0, %51 ]
store i32 %53, i32* %5
br label %54
54: ; preds = %52
%55 = load i32, i32* %5
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %72
58: ; preds = %54
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %9
%59 = load i8*, i8** %9
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %70
61: ; preds = %58
%62 = load i8*, i8** %9
%63 = load i32, i32* @stderr
%64 = call i32 @fputs(i8* %62, i32 %63)
%65 = load i32, i32* @stderr
%66 = load i32, i32* %8
%67 = sub nsw i32 0, %66
%68 = call i8* @strerror(i32 %67)
%69 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %61, %58
%71 = load i32, i32* %5
store i32 %71, i32* %2
br label %75
72: ; preds = %54
br label %73
73: ; preds = %72
%74 = load i32, i32* %5
store i32 %74, i32* %2
br label %75
75: ; preds = %73, %70, %41
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i32 0
@.str = [5 x i8] c"open\00"
@stderr = global i32 0
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [6 x i8] c"close\00"
define i32 @touch(i8* nocapture %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_EXCL
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* %0, i32 %6, i32 493)
%8 = icmp slt i32 %7, 0
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
%11 = select i1 %8, i32 %10, i32 0
%12 = icmp slt i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %1
%14 = tail call i64 @close(i32 %7)
%15 = icmp slt i64 %14, 0
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
%18 = select i1 %15, i32 %17, i32 0
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %13, %1
%21 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %13 ]
%22 = phi i32 [ %11, %1 ], [ %18, %13 ]
%23 = phi i32 [ %10, %1 ], [ %17, %13 ]
%24 = load i32, i32* @stderr
%25 = tail call i32 @fputs(i8* %21, i32 %24)
%26 = load i32, i32* @stderr
%27 = sub nsw i32 0, %22
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %20, %13
%31 = phi i32 [ %18, %13 ], [ %23, %20 ]
ret i32 %31
}