#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ link(char *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ symlink(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *path = argv[1];
  struct stat buf;
  int i = stat(path, &buf);
  if (i == -1) {
    perror("stat");
    return -1;
  }
  if (!S_ISREG(buf.st_mode)) {
    printf("It is not a regular file");
    return -1;
  }
  char *newsym = malloc(sizeof(char) * strlen(path) + 5);
  strcpy(newsym, path);
  symlink(path, strcat(newsym, ".sym"));
  free(newsym);
  char *newfis = malloc(sizeof(char) * strlen(path) + 6);
  strcpy(newfis, path);
  link(path, strcat(newfis, ".hard"));
  free(newfis);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1204 <main+0x54>
lea    0xe0d(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <main+0x12b>
mov    -0x20(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%eax
jne    122d <main+0x7d>
lea    0xde9(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <main+0x12b>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x5,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1070 <symlink@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x6,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   10d0 <link@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     1277 <main+0xc7>
mov    (%rsp),%edi
call   1090 <S_ISREG@plt>
test   %eax,%eax
je     125e <main+0xae>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x5(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <symlink@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x6(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xde3(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10d0 <link@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    126f <main+0xbf>
lea    0xda0(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd82(%rip),%rdi
call   10b0 <perror@plt>
jmp    126a <main+0xba>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [25 x i8] c"It is not a regular file\00"
@.str.2 = [5 x i8] c".sym\00"
@.str.3 = [6 x i8] c".hard\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i32 @stat(i8* %14, %struct.stat* %7)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %60
20: ; preds = %2
%21 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @S_ISREG(i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %60
27: ; preds = %20
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = mul i64 1, %30
%32 = add i64 %31, 5
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = load i8*, i8** %6
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %6
%39 = load i8*, i8** %9
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @symlink(i8* %38, i32 %40)
%42 = load i8*, i8** %9
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %6
%45 = call i32 @strlen(i8* %44)
%46 = sext i32 %45 to i64
%47 = mul i64 1, %46
%48 = add i64 %47, 6
%49 = trunc i64 %48 to i32
%50 = call i8* @malloc(i32 %49)
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = load i8*, i8** %6
%53 = call i32 @strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %6
%55 = load i8*, i8** %10
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @link(i8* %54, i32 %56)
%58 = load i8*, i8** %10
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %27, %25, %18
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [25 x i8] c"It is not a regular file\00"
@.str.2 = [5 x i8] c".sym\00"
@.str.3 = [6 x i8] c".hard\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i32 @stat(i8* %5, %struct.stat* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %33
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @S_ISREG(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %33
18: ; preds = %11
%19 = tail call i32 @strlen(i8* %5)
%20 = add i32 %19, 5
%21 = tail call i8* @malloc(i32 %20)
%22 = tail call i32 @strcpy(i8* %21, i8* %5)
%23 = tail call i32 @strcat(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @symlink(i8* %5, i32 %23)
%25 = tail call i32 @free(i8* %21)
%26 = tail call i32 @strlen(i8* %5)
%27 = add i32 %26, 6
%28 = tail call i8* @malloc(i32 %27)
%29 = tail call i32 @strcpy(i8* %28, i8* %5)
%30 = tail call i32 @strcat(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @link(i8* %5, i32 %30)
%32 = tail call i32 @free(i8* %28)
br label %33
33: ; preds = %18, %16, %9
%34 = phi i32 [ -1, %9 ], [ 0, %18 ], [ -1, %16 ]
ret i32 %34
}