#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;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int strlen(char *);
int pushin(char *fname, char *dir, char *output) {
  struct stat st;
  FILE *fp, *fp2;
  char buf[1025];
  if (!(stat(fname, &st) == 0 && S_ISREG(st.st_mode)))
    return 2;
  fp = fopen(output, "a");
  fp2 = fopen(fname, "r");
  if (fp == NULL || fp2 == NULL)
    return 3;
  fprintf(fp, ">%s:%s:<%c\n", dir, fname, 31);
  while (fgets(buf, 1024, fp2) != NULL)
    fputs(buf, fp);
  if (buf[strlen(buf) - 1] != '\n')
    fputs("\n", fp);
  fclose(fp);
  fclose(fp2);
}


x86 assembly (clang, -O0):
<pushin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jne    11c0 <pushin+0x40>
mov    -0x28(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
jne    11cc <pushin+0x4c>
movl   $0x2,-0x4(%rbp)
jmp    12ac <pushin+0x12c>
mov    -0x20(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     120a <pushin+0x8a>
cmpq   $0x0,-0x38(%rbp)
jne    1216 <pushin+0x96>
movl   $0x3,-0x4(%rbp)
jmp    12ac <pushin+0x12c>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xddb(%rip),%rsi
mov    $0x1f,%r8d
call   1070 <fprintf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1268 <pushin+0xe8>
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1234 <pushin+0xb4>
lea    -0x440(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x440(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     129a <pushin+0x11a>
mov    -0x30(%rbp),%rsi
lea    0xd79(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pushin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     11ce <pushin+0x3e>
mov    %ebp,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%edi
call   10a0 <S_ISREG@plt>
test   %rax,%rax
je     11bc <pushin+0x2c>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe0d(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
mov    $0x3,%ebp
test   %rbx,%rbx
je     11bc <pushin+0x2c>
mov    %rax,%r14
test   %rax,%rax
je     11bc <pushin+0x2c>
lea    0xdee(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    $0x1f,%r8d
call   1080 <fprintf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1270 <pushin+0xe0>
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1250 <pushin+0xc0>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
je     128f <pushin+0xff>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    11bc <pushin+0x2c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c">%s:%s:<%c\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @pushin(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [1025 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %5
%13 = call i64 @stat(i8* %12, %struct.stat* %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @S_ISREG(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15, %3
store i32 2, i32* %4
br label %63
21: ; preds = %15
%22 = load i8*, i8** %7
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %9
%24 = load i8*, i8** %5
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %9
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i32*, i32** %10
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %28, %21
store i32 3, i32* %4
br label %63
32: ; preds = %28
%33 = load i32*, i32** %9
%34 = load i8*, i8** %6
%35 = load i8*, i8** %5
%36 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %35, i32 31)
br label %37
37: ; preds = %42, %32
%38 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%39 = load i32*, i32** %10
%40 = call i32* @fgets(i8* %38, i32 1024, i32* %39)
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%44 = load i32*, i32** %9
%45 = call i32 @fputs(i8* %43, i32* %44)
br label %37
46: ; preds = %37
%47 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 10
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = load i32*, i32** %9
%57 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %56)
br label %58
58: ; preds = %55, %46
%59 = load i32*, i32** %9
%60 = call i32 @fclose(i32* %59)
%61 = load i32*, i32** %10
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %58, %31, %20
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c">%s:%s:<%c\0A\00"
define i32 @pushin(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca %struct.stat
%5 = alloca [1025 x i8]
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%8 = call i64 @stat(i8* %0, %struct.stat* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %41
10: ; preds = %3
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISREG(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %41, label %15
15: ; preds = %10
%16 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %16, null
%19 = icmp eq i32* %17, null
%20 = or i1 %18, %19
br i1 %20, label %41, label %21
21: ; preds = %15
%22 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %0, i32 31)
%23 = call i32* @fgets(i8* %7, i32 1024, i32* %17)
%24 = icmp eq i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %21, %25
%26 = call i32 @fputs(i8* %7, i32* %16)
%27 = call i32* @fgets(i8* %7, i32 1024, i32* %17)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %25
29: ; preds = %25, %21
%30 = call i32 @strlen(i8* %7)
%31 = add nsw i32 %30, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 10
br i1 %35, label %38, label %36
36: ; preds = %29
%37 = call i32 @fputc(i32 10, i32* %16)
br label %38
38: ; preds = %36, %29
%39 = call i32 @fclose(i32* %16)
%40 = call i32 @fclose(i32* %17)
br label %41
41: ; preds = %15, %3, %10, %38
%42 = phi i32 [ undef, %38 ], [ 2, %10 ], [ 2, %3 ], [ 3, %15 ]
ret i32 %42
}