#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_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ symlink(char *, char *);
int main(int ac, char **av) {
  int fd;
  if ((fd = open(av[1], O_RDWR | O_CREAT,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) {
    perror("creat_slink: open() failed");
    exit(1);
  }
  if (close(fd) == -1) {
    perror("creat_slink: close() failed");
    exit(1);
  }
  if (symlink(av[1], av[2]) < 0) {
    perror("creat_slink: symlink() failed");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
or     (%rax),%esi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    0x2e48(%rip),%rax
or     (%rax),%edx
mov    0x2e2f(%rip),%rax
or     (%rax),%edx
mov    0x2e1e(%rip),%rax
or     (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <main+0x7b>
lea    0xe44(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11f2 <main+0xa2>
lea    0xe38(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <symlink@plt>
cmp    $0x0,%rax
jge    1227 <main+0xd7>
lea    0xe1f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rcx
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e4e(%rip),%rcx
mov    0x2e67(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %rsi,%rbx
mov    0x2e49(%rip),%rcx
or     (%rcx),%edx
mov    0x8(%rsi),%rdi
mov    0x2e34(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
jne    11a3 <main+0x53>
lea    0xe5f(%rip),%rdi
jmp    11d1 <main+0x81>
mov    %eax,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11b8 <main+0x68>
lea    0xe65(%rip),%rdi
jmp    11d1 <main+0x81>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1030 <symlink@plt>
test   %rax,%rax
jns    11e0 <main+0x90>
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [27 x i8] c"creat_slink: open() failed\00"
@.str.1 = [28 x i8] c"creat_slink: close() failed\00"
@.str.2 = [30 x i8] c"creat_slink: symlink() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IROTH
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %9, i32 %12, i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i64 @symlink(i8* %35, i8* %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [27 x i8] c"creat_slink: open() failed\00"
@.str.1 = [28 x i8] c"creat_slink: close() failed\00"
@.str.2 = [30 x i8] c"creat_slink: symlink() failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IROTH
%14 = or i32 %12, %13
%15 = tail call i32 @open(i8* %4, i32 %7, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = tail call i32 @close(i32 %15)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i64 @symlink(i8* %27, i8* %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = tail call i32 @exit(i32 0)
unreachable
}