#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_APPEND;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int create_file(char *);
char *get_next_line(int);
int /*<<< orphan*/ my_putchar(char);
int /*<<< orphan*/ my_putstr(char *);
int /*<<< orphan*/ my_strlen(char *);
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int built_alias(char **env, char **save) {
  char *str;
  int fd;
  (void)env;
  if ((fd = open("alias/alias", O_RDWR | O_APPEND, S_IRUSR | S_IWUSR)) == -1)
    fd = create_file("alias/alias");
  if (save[1] == NULL) {
    while ((str = get_next_line(fd))) {
      my_putstr(str);
      my_putchar('\n');
    }
  } else {
    write(fd, save[1], my_strlen(save[1]));
    write(fd, "\n", my_strlen("\n"));
  }
  return (0);
}


x86 assembly (clang, -O0):
<built_alias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    0x2e3e(%rip),%rax
or     (%rax),%edx
lea    0xe55(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <built_alias+0x5b>
lea    0xe3d(%rip),%rdi
call   1080 <create_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1212 <built_alias+0xa2>
jmp    11df <built_alias+0x6f>
mov    -0x1c(%rbp),%edi
call   1090 <get_next_line@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     120d <built_alias+0x9d>
mov    -0x18(%rbp),%rdi
call   1060 <my_putstr@plt>
mov    $0xa,%edi
call   1050 <my_putchar@plt>
jmp    11df <built_alias+0x6f>
jmp    1262 <built_alias+0xf2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <my_strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    0xdc0(%rip),%rdi
call   1030 <my_strlen@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xdaf(%rip),%rsi
call   1040 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<built_alias>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e6a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e40(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe5e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11bc <built_alias+0x4c>
lea    0xe4b(%rip),%rdi
call   1080 <create_file@plt>
mov    %eax,%ebx
mov    0x8(%r14),%r14
test   %r14,%r14
je     1212 <built_alias+0xa2>
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe2c(%rip),%r14
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    121e <built_alias+0xae>
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1060 <my_putstr@plt>
mov    $0xa,%edi
call   1050 <my_putchar@plt>
mov    %ebx,%edi
call   1090 <get_next_line@plt>
test   %rax,%rax
jne    1200 <built_alias+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"alias/alias\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @built_alias(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %3
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_APPEND
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @create_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %6
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %33
23: ; preds = %18
br label %24
24: ; preds = %28, %23
%25 = load i32, i32* %6
%26 = call i8* @get_next_line(i32 %25)
store i8* %26, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = call i32 @my_putstr(i8* %29)
%31 = call i32 @my_putchar(i8 signext 10)
br label %24
32: ; preds = %24
br label %46
33: ; preds = %18
%34 = load i32, i32* %6
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @my_strlen(i8* %40)
%42 = call i32 @write(i32 %34, i8* %37, i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @my_strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = call i32 @write(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %33, %32
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"alias/alias\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @built_alias(i8** nocapture readnone %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_APPEND
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @create_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = phi i32 [ %12, %11 ], [ %9, %2 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = tail call i8* @get_next_line(i32 %14)
%20 = icmp eq i8* %19, null
br i1 %20, label %32, label %21
21: ; preds = %18, %21
%22 = phi i8* [ %25, %21 ], [ %19, %18 ]
%23 = tail call i32 @my_putstr(i8* %22)
%24 = tail call i32 @my_putchar(i8 signext 10)
%25 = tail call i8* @get_next_line(i32 %14)
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %21
27: ; preds = %13
%28 = tail call i32 @my_strlen(i8* %16)
%29 = tail call i32 @write(i32 %14, i8* %16, i32 %28)
%30 = tail call i32 @my_strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %21, %18, %27
ret i32 0
}