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

/* Variables and functions */
int /*<<< orphan*/ EX_OSERR;
char *ctime(int /*<<< orphan*/ *);
int dup(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ index(char *, char);
int /*<<< orphan*/ logerr(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcmp(char *, char *, int);
int mkstemp(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
char *strdup(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int store(const char *from) {
  FILE *fp = NULL;
  time_t tval;
  int fd, eline;
  char *tn, line[2048];
  tn = strdup("/tmp/local.XXXXXX");
  if (!tn)
    logerr(EX_OSERR, "not enough core");
  if ((fd = mkstemp(tn)) == -1 || !(fp = fdopen(fd, "w+")))
    logerr(EX_OSERR, "unable to open temporary file");
  (void)unlink(tn);
  free(tn);
  (void)time(&tval);
  (void)fprintf(fp, "From %s %s", from, ctime(&tval));
  line[0] = '\0';
  for (eline = 1; fgets(line, sizeof(line), stdin);) {
    if (line[0] == '\n')
      eline = 1;
    else {
      if (eline && line[0] == 'F' && !memcmp(line, "From ", 5))
        (void)putc('>', fp);
      eline = 0;
    }
    (void)fprintf(fp, "%s", line);
    if (ferror(fp))
      break;
  }
  if (!index(line, '\n'))
    (void)putc('\n', fp);
  (void)putc('\n', fp);
  (void)fflush(fp);
  if (ferror(fp))
    logerr(EX_OSERR, "temporary file write error");
  fd = dup(fd);
  (void)fclose(fp);
  return (fd);
}


x86 assembly (clang, -O0):
<store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xdd2(%rip),%rdi
call   1130 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1257 <store+0x47>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
call   10e0 <logerr@plt>
mov    -0x28(%rbp),%rdi
call   1110 <mkstemp@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1289 <store+0x79>
mov    -0x18(%rbp),%edi
lea    0xdac(%rip),%rsi
call   1120 <fdopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    129e <store+0x8e>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   10e0 <logerr@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    -0x14(%rbp),%rdi
call   10f0 <time@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <ctime@plt>
mov    -0x840(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    %rax,%rcx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movb   $0x0,-0x830(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    -0x830(%rbp),%rdi
mov    0x2cd5(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     13cb <store+0x1bb>
movsbl -0x830(%rbp),%eax
cmp    $0xa,%eax
jne    1345 <store+0x135>
movl   $0x1,-0x1c(%rbp)
jmp    1395 <store+0x185>
cmpl   $0x0,-0x1c(%rbp)
je     138e <store+0x17e>
movsbl -0x830(%rbp),%eax
cmp    $0x46,%eax
jne    138e <store+0x17e>
lea    -0x830(%rbp),%rdi
lea    0xce1(%rip),%rsi
mov    $0x5,%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%eax
jne    138e <store+0x17e>
mov    -0x10(%rbp),%rsi
mov    $0x3e,%edi
call   10c0 <putc@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x830(%rbp),%rdx
lea    0xca4(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     13c6 <store+0x1b6>
jmp    13cb <store+0x1bb>
jmp    1305 <store+0xf5>
lea    -0x830(%rbp),%rdi
mov    $0xa,%esi
call   1090 <index@plt>
cmp    $0x0,%eax
jne    13f3 <store+0x1e3>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   10c0 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   10c0 <putc@plt>
mov    -0x10(%rbp),%rdi
call   1100 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1432 <store+0x222>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc27(%rip),%rsi
call   10e0 <logerr@plt>
mov    -0x18(%rbp),%edi
call   1080 <dup@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r15
lea    0xdc5(%rip),%rdi
call   1140 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    125d <store+0x3d>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
call   10f0 <logerr@plt>
mov    %r14,%rdi
call   1120 <mkstemp@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1282 <store+0x62>
lea    0xdaf(%rip),%rsi
mov    %ebp,%edi
call   1130 <fdopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1299 <store+0x79>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
call   10f0 <logerr@plt>
xor    %ebx,%ebx
mov    %ebp,0x8(%rsp)
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1100 <time@plt>
mov    %rbp,%rdi
call   1070 <ctime@plt>
lea    0xd7a(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10e0 <fprintf@plt>
movb   $0x0,0x10(%rsp)
mov    $0x1,%ebp
mov    0x2cfe(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xd58(%rip),%r15
jmp    131b <store+0xfb>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1090 <fputs@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
mov    %r14d,%ebp
test   %rax,%rax
jne    136e <store+0x14e>
mov    (%r12),%edx
mov    %r13,%rdi
mov    $0x800,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
je     136e <store+0x14e>
movzbl 0x10(%rsp),%eax
mov    $0x1,%r14d
cmp    $0xa,%al
je     1300 <store+0xe0>
xor    %r14d,%r14d
test   %ebp,%ebp
je     1300 <store+0xe0>
cmp    $0x46,%al
jne    1300 <store+0xe0>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   10b0 <memcmp@plt>
test   %eax,%eax
jne    1300 <store+0xe0>
mov    $0x3e,%edi
mov    %rbx,%rsi
call   10d0 <putc@plt>
jmp    1300 <store+0xe0>
lea    0x10(%rsp),%rdi
mov    $0xa,%esi
call   10a0 <index@plt>
test   %eax,%eax
jne    138e <store+0x16e>
mov    $0xa,%edi
mov    %rbx,%rsi
call   10d0 <putc@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   10d0 <putc@plt>
mov    %rbx,%rdi
call   1110 <fflush@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
mov    0x8(%rsp),%ebp
je     13c9 <store+0x1a9>
mov    0x2c1d(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
call   10f0 <logerr@plt>
mov    %ebp,%edi
call   1080 <dup@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %ebp,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/tmp/local.XXXXXX\00"
@EX_OSERR = global i32 0
@.str.1 = [16 x i8] c"not enough core\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [30 x i8] c"unable to open temporary file\00"
@.str.4 = [11 x i8] c"From %s %s\00"
@stdin = global i32 0
@.str.5 = [6 x i8] c"From \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [27 x i8] c"temporary file write error\00"
define i32 @store(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [2048 x i8]
store i8* %0, i8** %2
store i32* null, i32** %3
%9 = call i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* @EX_OSERR
%14 = call i32 @logerr(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %1
%16 = load i8*, i8** %7
%17 = call i32 @mkstemp(i8* %16)
store i32 %17, i32* %5
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* %5
%21 = call i32* @fdopen(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %3
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %19, %15
%24 = load i32, i32* @EX_OSERR
%25 = call i32 @logerr(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %23, %19
%27 = load i8*, i8** %7
%28 = call i32 @unlink(i8* %27)
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
%31 = call i32 @time(i32* %4)
%32 = load i32*, i32** %3
%33 = load i8*, i8** %2
%34 = call i8* @ctime(i32* %4)
%35 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34)
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
store i8 0, i8* %36
store i32 1, i32* %6
br label %37
37: ; preds = %72, %26
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* @stdin
%40 = call i64 @fgets(i8* %38, i32 2048, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %73
42: ; preds = %37
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 1, i32* %6
br label %64
48: ; preds = %42
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 70
br i1 %55, label %56, label %63
56: ; preds = %51
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%58 = call i32 @memcmp(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%59 = icmp ne i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %56
%61 = load i32*, i32** %3
%62 = call i32 @putc(i8 signext 62, i32* %61)
br label %63
63: ; preds = %60, %56, %51, %48
store i32 0, i32* %6
br label %64
64: ; preds = %63, %47
%65 = load i32*, i32** %3
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%67 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %3
%69 = call i64 @ferror(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %64
br label %73
72: ; preds = %64
br label %37
73: ; preds = %71, %37
%74 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%75 = call i32 @index(i8* %74, i8 signext 10)
%76 = icmp ne i32 %75, 0
br i1 %76, label %80, label %77
77: ; preds = %73
%78 = load i32*, i32** %3
%79 = call i32 @putc(i8 signext 10, i32* %78)
br label %80
80: ; preds = %77, %73
%81 = load i32*, i32** %3
%82 = call i32 @putc(i8 signext 10, i32* %81)
%83 = load i32*, i32** %3
%84 = call i32 @fflush(i32* %83)
%85 = load i32*, i32** %3
%86 = call i64 @ferror(i32* %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %80
%89 = load i32, i32* @EX_OSERR
%90 = call i32 @logerr(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %91
91: ; preds = %88, %80
%92 = load i32, i32* %5
%93 = call i32 @dup(i32 %92)
store i32 %93, i32* %5
%94 = load i32*, i32** %3
%95 = call i32 @fclose(i32* %94)
%96 = load i32, i32* %5
ret i32 %96
}

LLVM IR (-O2):
@.str = [18 x i8] c"/tmp/local.XXXXXX\00"
@EX_OSERR = global i32 0
@.str.1 = [16 x i8] c"not enough core\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [30 x i8] c"unable to open temporary file\00"
@.str.4 = [11 x i8] c"From %s %s\00"
@stdin = global i32 0
@.str.5 = [6 x i8] c"From \00"
@.str.7 = [27 x i8] c"temporary file write error\00"
define i32 @store(i8* %0) {
%2 = alloca i32
%3 = alloca [2048 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = tail call dereferenceable_or_null(18) i8* @strdup(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @EX_OSERR
%10 = tail call i32 @logerr(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %1
%12 = tail call i32 @mkstemp(i8* %6)
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32* @fdopen(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14, %11
%18 = load i32, i32* @EX_OSERR
%19 = tail call i32 @logerr(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = phi i32* [ null, %17 ], [ %15, %14 ]
%22 = tail call i32 @unlink(i8* %6)
%23 = tail call i32 @free(i8* %6)
%24 = call i32 @time(i32* %2)
%25 = call i8* @ctime(i32* %2)
%26 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %25)
store i8 0, i8* %5
br label %27
27: ; preds = %44, %20
%28 = phi i32 [ 1, %20 ], [ %45, %44 ]
%29 = load i32, i32* @stdin
%30 = call i64 @fgets(i8* %5, i32 2048, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %49, label %32
32: ; preds = %27
%33 = load i8, i8* %5
%34 = icmp eq i8 %33, 10
br i1 %34, label %44, label %35
35: ; preds = %32
%36 = icmp ne i32 %28, 0
%37 = icmp eq i8 %33, 70
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = call i32 @memcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @putc(i8 signext 62, i32* %21)
br label %44
44: ; preds = %35, %39, %42, %32
%45 = phi i32 [ 1, %32 ], [ 0, %42 ], [ 0, %39 ], [ 0, %35 ]
%46 = call i32 @fputs(i8* %5, i32* %21)
%47 = call i64 @ferror(i32* %21)
%48 = icmp eq i64 %47, 0
br i1 %48, label %27, label %49
49: ; preds = %44, %27
%50 = call i32 @index(i8* %5, i8 signext 10)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 @putc(i8 signext 10, i32* %21)
br label %54
54: ; preds = %52, %49
%55 = call i32 @putc(i8 signext 10, i32* %21)
%56 = call i32 @fflush(i32* %21)
%57 = call i64 @ferror(i32* %21)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %54
%60 = load i32, i32* @EX_OSERR
%61 = call i32 @logerr(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %62
62: ; preds = %59, %54
%63 = call i32 @dup(i32 %12)
%64 = call i32 @fclose(i32* %21)
ret i32 %63
}