#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 Buf {
  int dummy;
};

/* Variables and functions */
struct Buf *buf_strappend(struct Buf *, char *);
char *flex_alloc(int);
int /*<<< orphan*/ flex_free(char *);
int /*<<< orphan*/ flexfatal(char *);
int sprintf(char *, char *, int);
int strlen(char const *);
struct Buf *buf_linedir(struct Buf *buf, const char *filename, int lineno) {
  char *dst, *t;
  const char *src;
  t = flex_alloc(strlen("#line \"\"\n") + 2 * strlen(filename) + 10 + 1);
  if (!t)
    flexfatal("Allocation of buffer for line directive failed");
  for (dst = t + sprintf(t, "#line %d \"", lineno), src = filename; *src;
       *dst++ = *src++)
    if (*src == '\\')
      *dst++ = '\\';
  *dst++ = '"';
  *dst++ = '\n';
  *dst = '\0';
  buf = buf_strappend(buf, t);
  flex_free(t);
  return buf;
}


x86 assembly (clang, -O0):
<buf_linedir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe86(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
shl    $0x1,%eax
add    %eax,%edi
add    $0xa,%edi
add    $0x1,%edi
call   1040 <flex_alloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b9 <buf_linedir+0x59>
lea    0xe56(%rip),%rdi
call   1080 <flexfatal@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe6a(%rip),%rsi
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1247 <buf_linedir+0xe7>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    121b <buf_linedir+0xbb>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
jmp    1220 <buf_linedir+0xc0>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11ec <buf_linedir+0x8c>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x22,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0xa,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <buf_strappend@plt>
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <flex_free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_linedir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe88(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xb(%rbp,%rax,2),%edi
call   1040 <flex_alloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11a4 <buf_linedir+0x44>
lea    0xe6b(%rip),%rdi
call   1080 <flexfatal@plt>
lea    0xe8e(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
call   1060 <sprintf@plt>
movslq %eax,%rcx
mov    %r15,%rax
add    %rcx,%rax
jmp    11e4 <buf_linedir+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x5c,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
cmp    $0x5c,%cl
je     11d0 <buf_linedir+0x70>
test   %cl,%cl
jne    11da <buf_linedir+0x7a>
movw   $0xa22,(%rax)
movb   $0x0,0x2(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <buf_strappend@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <flex_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Buf = type { i32 }
@.str = [10 x i8] c"#line \22\22\0A\00"
@.str.1 = [47 x i8] c"Allocation of buffer for line directive failed\00"
@.str.2 = [11 x i8] c"#line %d \22\00"
define %struct.Buf* @buf_linedir(%struct.Buf* %0, i8* %1, i32 %2) {
%4 = alloca %struct.Buf*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store %struct.Buf* %0, %struct.Buf** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = mul nsw i32 2, %12
%14 = add nsw i32 %10, %13
%15 = add nsw i32 %14, 10
%16 = add nsw i32 %15, 1
%17 = call i8* @flex_alloc(i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %3
%21 = call i32 @flexfatal(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i8*, i8** %8
%24 = load i8*, i8** %8
%25 = load i32, i32* %6
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8* %28, i8** %7
%29 = load i8*, i8** %5
store i8* %29, i8** %9
br label %30
30: ; preds = %43, %22
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %49
34: ; preds = %30
%35 = load i8*, i8** %9
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 92
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %7
store i8 92, i8* %40
br label %42
42: ; preds = %39, %34
br label %43
43: ; preds = %42
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %9
%46 = load i8, i8* %44
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 %46, i8* %47
br label %30
49: ; preds = %30
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
store i8 34, i8* %50
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %7
store i8 10, i8* %52
%54 = load i8*, i8** %7
store i8 0, i8* %54
%55 = load %struct.Buf*, %struct.Buf** %4
%56 = load i8*, i8** %8
%57 = call %struct.Buf* @buf_strappend(%struct.Buf* %55, i8* %56)
store %struct.Buf* %57, %struct.Buf** %4
%58 = load i8*, i8** %8
%59 = call i32 @flex_free(i8* %58)
%60 = load %struct.Buf*, %struct.Buf** %4
ret %struct.Buf* %60
}

LLVM IR (-O2):
%struct.Buf = type { i32 }
@.str = [10 x i8] c"#line \22\22\0A\00"
@.str.1 = [47 x i8] c"Allocation of buffer for line directive failed\00"
@.str.2 = [11 x i8] c"#line %d \22\00"
define %struct.Buf* @buf_linedir(%struct.Buf* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = shl nsw i32 %5, 1
%7 = add i32 %4, 11
%8 = add i32 %7, %6
%9 = tail call i8* @flex_alloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @flexfatal(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %9, i64 %15
br label %17
17: ; preds = %24, %13
%18 = phi i8* [ %16, %13 ], [ %28, %24 ]
%19 = phi i8* [ %1, %13 ], [ %27, %24 ]
%20 = load i8, i8* %19
switch i8 %20, label %24 [
i8 0, label %29
i8 92, label %21
]
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %18, i64 1
store i8 92, i8* %18
%23 = load i8, i8* %19
br label %24
24: ; preds = %17, %21
%25 = phi i8 [ %23, %21 ], [ %20, %17 ]
%26 = phi i8* [ %22, %21 ], [ %18, %17 ]
%27 = getelementptr inbounds i8, i8* %19, i64 1
%28 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %25, i8* %26
br label %17
29: ; preds = %17
%30 = getelementptr inbounds i8, i8* %18, i64 1
store i8 34, i8* %18
%31 = getelementptr inbounds i8, i8* %18, i64 2
store i8 10, i8* %30
store i8 0, i8* %31
%32 = tail call %struct.Buf* @buf_strappend(%struct.Buf* %0, i8* %9)
%33 = tail call i32 @flex_free(i8* %9)
ret %struct.Buf* %32
}