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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ add(unsigned char *);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getchar();
scalar_t__ isspace(unsigned char);
unsigned char *strchr(char *, char);
int /*<<< orphan*/ warnx(char *);
void addfile(char *name) {
  unsigned char *p;
  FILE *fp;
  int ch;
  char buf[2048 + 1];
  if ((fp = fopen(name, "r")) == NULL)
    err(1, "%s", name);
  while (fgets(buf, sizeof(buf), fp)) {
    if (!(p = strchr(buf, '\n'))) {
      warnx("line too long");
      while ((ch = getchar()) != '\n' && ch != EOF)
        ;
      continue;
    }
    *p = '\0';
    for (p = buf; *p && isspace(*p); ++p)
      ;
    if (!*p || *p == '#')
      continue;
    add(p);
  }
  (void)fclose(fp);
}


x86 assembly (clang, -O0):
<addfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d2 <addfile+0x42>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe35(%rip),%rsi
call   10a0 <err@plt>
jmp    11d7 <addfile+0x47>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x801,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     130c <addfile+0x17c>
lea    -0x820(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1270 <addfile+0xe0>
lea    0xde9(%rip),%rdi
call   1060 <warnx@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x821(%rbp)
je     1253 <addfile+0xc3>
mov    -0x1c(%rbp),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x821(%rbp)
mov    -0x821(%rbp),%al
test   $0x1,%al
jne    1266 <addfile+0xd6>
jmp    126b <addfile+0xdb>
jmp    1221 <addfile+0x91>
jmp    11d7 <addfile+0x47>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x820(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x822(%rbp)
je     12b3 <addfile+0x123>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x822(%rbp)
mov    -0x822(%rbp),%al
test   $0x1,%al
jne    12c6 <addfile+0x136>
jmp    12dc <addfile+0x14c>
jmp    12cb <addfile+0x13b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1282 <addfile+0xf2>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12f9 <addfile+0x169>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x23,%eax
jne    12fe <addfile+0x16e>
jmp    11d7 <addfile+0x47>
mov    -0x10(%rbp),%rdi
call   1030 <add@plt>
jmp    11d7 <addfile+0x47>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addfile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    %rdi,%rbx
lea    0xe56(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11cb <addfile+0x3b>
lea    0xe44(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   10a0 <err@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x801,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12a6 <addfile+0x116>
lea    0xe17(%rip),%r15
mov    0x2df3(%rip),%r13
jmp    1219 <addfile+0x89>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x801,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12a6 <addfile+0x116>
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1260 <addfile+0xd0>
movb   $0x0,(%rax)
mov    (%rsp),%al
test   %al,%al
je     1200 <addfile+0x70>
mov    %r12,%rbx
nopl   0x0(%rax,%rax,1)
movzbl %al,%edi
call   1070 <isspace@plt>
test   %rax,%rax
je     1287 <addfile+0xf7>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1240 <addfile+0xb0>
jmp    1200 <addfile+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <warnx@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%eax
je     1200 <addfile+0x70>
cmp    0x0(%r13),%eax
jne    1270 <addfile+0xe0>
jmp    1200 <addfile+0x70>
mov    (%rbx),%al
cmp    $0x23,%al
je     1200 <addfile+0x70>
test   %al,%al
je     1200 <addfile+0x70>
mov    %rbx,%rdi
call   1030 <add@plt>
jmp    1200 <addfile+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"line too long\00"
@EOF = global i32 0
define void @addfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [2049 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %1
br label %14
14: ; preds = %65, %64, %35, %13
%15 = getelementptr inbounds [2049 x i8], [2049 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 2049, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %68
19: ; preds = %14
%20 = getelementptr inbounds [2049 x i8], [2049 x i8]* %6, i64 0, i64 0
%21 = call i8* @strchr(i8* %20, i8 signext 10)
store i8* %21, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %36, label %23
23: ; preds = %19
%24 = call i32 @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %34, %23
%26 = call i32 (...) @getchar()
store i32 %26, i32* %5
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load i32, i32* @EOF
%31 = icmp ne i32 %29, %30
br label %32
32: ; preds = %28, %25
%33 = phi i1 [ false, %25 ], [ %31, %28 ]
br i1 %33, label %34, label %35
34: ; preds = %32
br label %25
35: ; preds = %32
br label %14
36: ; preds = %19
%37 = load i8*, i8** %3
store i8 0, i8* %37
%38 = getelementptr inbounds [2049 x i8], [2049 x i8]* %6, i64 0, i64 0
store i8* %38, i8** %3
br label %39
39: ; preds = %52, %36
%40 = load i8*, i8** %3
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i8*, i8** %3
%46 = load i8, i8* %45
%47 = call i64 @isspace(i8 zeroext %46)
%48 = icmp ne i64 %47, 0
br label %49
49: ; preds = %44, %39
%50 = phi i1 [ false, %39 ], [ %48, %44 ]
br i1 %50, label %51, label %55
51: ; preds = %49
br label %52
52: ; preds = %51
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %3
br label %39
55: ; preds = %49
%56 = load i8*, i8** %3
%57 = load i8, i8* %56
%58 = icmp ne i8 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i8*, i8** %3
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %62, 35
br i1 %63, label %64, label %65
64: ; preds = %59, %55
br label %14
65: ; preds = %59
%66 = load i8*, i8** %3
%67 = call i32 @add(i8* %66)
br label %14
68: ; preds = %14
%69 = load i32*, i32** %4
%70 = call i32 @fclose(i32* %69)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [14 x i8] c"line too long\00"
@EOF = global i32 0
define void @addfile(i8* %0) {
%2 = alloca [2049 x i8]
%3 = getelementptr inbounds [2049 x i8], [2049 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = call i64 @fgets(i8* %3, i32 2049, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %41, label %11
11: ; preds = %8, %36
%12 = call i8* @strchr(i8* %3, i8 signext 10)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = call i32 @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %16, %14
%17 = call i32 (...) @getchar()
%18 = icmp ne i32 %17, 10
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %17, %19
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %16, label %36
22: ; preds = %11
store i8 0, i8* %12
%23 = load i8, i8* %3
%24 = icmp eq i8 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %22, %30
%26 = phi i8 [ %32, %30 ], [ %23, %22 ]
%27 = phi i8* [ %31, %30 ], [ %3, %22 ]
%28 = call i64 @isspace(i8 zeroext %26)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %27, i64 1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %25
34: ; preds = %25
%35 = load i8, i8* %27
switch i8 %35, label %39 [
i8 0, label %36
i8 35, label %36
]
36: ; preds = %30, %16, %34, %34, %22, %39
%37 = call i64 @fgets(i8* %3, i32 2049, i32* %4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %11
39: ; preds = %34
%40 = call i32 @add(i8* %27)
br label %36
41: ; preds = %36, %8
%42 = call i32 @fclose(i32* %4)
ret void
}