#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(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getchar();
scalar_t__ isspace(unsigned char);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
void addfile(char *name) {
  char *p;
  FILE *fp;
  int ch;
  char buf[2048 + 1];
  if ((fp = fopen(name, "r")) == NULL) {
    (void)fprintf(stderr, ("hexdump: can't read %s.\n"), name);
    exit(1);
  }
  while (fgets(buf, sizeof(buf), fp)) {
    if ((p = strchr(buf, '\n')) == NULL) {
      (void)fprintf(stderr, ("hexdump: line too long.\n"));
      while ((ch = getchar()) != '\n' && ch != EOF)
        ;
      continue;
    }
    *p = '\0';
    for (p = buf; *p && isspace((unsigned char)*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   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e2 <addfile+0x52>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    11e7 <addfile+0x57>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x801,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1327 <addfile+0x197>
lea    -0x820(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    128b <addfile+0xfb>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x821(%rbp)
je     126e <addfile+0xde>
mov    -0x1c(%rbp),%eax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x821(%rbp)
mov    -0x821(%rbp),%al
test   $0x1,%al
jne    1281 <addfile+0xf1>
jmp    1286 <addfile+0xf6>
jmp    123c <addfile+0xac>
jmp    11e7 <addfile+0x57>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x820(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x822(%rbp)
je     12ce <addfile+0x13e>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x822(%rbp)
mov    -0x822(%rbp),%al
test   $0x1,%al
jne    12e1 <addfile+0x151>
jmp    12f7 <addfile+0x167>
jmp    12e6 <addfile+0x156>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    129d <addfile+0x10d>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1314 <addfile+0x184>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1319 <addfile+0x189>
jmp    11e7 <addfile+0x57>
mov    -0x10(%rbp),%rdi
call   1030 <add@plt>
jmp    11e7 <addfile+0x57>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%rbx
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12af <addfile+0x11f>
mov    %rax,%r14
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x801,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1295 <addfile+0x105>
mov    0x2df9(%rip),%r13
lea    0xe35(%rip),%r15
mov    0x2dfb(%rip),%rbp
jmp    1209 <addfile+0x79>
nop
mov    %r12,%rdi
mov    $0x801,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1295 <addfile+0x105>
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1250 <addfile+0xc0>
movb   $0x0,(%rax)
mov    (%rsp),%al
test   %al,%al
je     11f0 <addfile+0x60>
mov    %r12,%rbx
nopl   0x0(%rax,%rax,1)
movzbl %al,%edi
call   1060 <isspace@plt>
test   %rax,%rax
je     1276 <addfile+0xe6>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1230 <addfile+0xa0>
jmp    11f0 <addfile+0x60>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%eax
je     11f0 <addfile+0x60>
cmp    0x0(%rbp),%eax
jne    1260 <addfile+0xd0>
jmp    11f0 <addfile+0x60>
mov    (%rbx),%al
cmp    $0x23,%al
je     11f0 <addfile+0x60>
test   %al,%al
je     11f0 <addfile+0x60>
mov    %rbx,%rdi
call   1030 <add@plt>
jmp    11f0 <addfile+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"hexdump: can't read %s.\0A\00"
@.str.2 = [25 x i8] c"hexdump: line too long.\0A\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 %9, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 2049, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %44, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %39
%14 = call i8* @strchr(i8* %3, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %19, %16
%20 = call i32 (...) @getchar()
%21 = icmp ne i32 %20, 10
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %20, %22
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %19, label %39
25: ; preds = %13
store i8 0, i8* %14
%26 = load i8, i8* %3
%27 = icmp eq i8 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %25, %33
%29 = phi i8 [ %35, %33 ], [ %26, %25 ]
%30 = phi i8* [ %34, %33 ], [ %3, %25 ]
%31 = call i64 @isspace(i8 zeroext %29)
%32 = icmp eq i64 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = getelementptr inbounds i8, i8* %30, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %39, label %28
37: ; preds = %28
%38 = load i8, i8* %30
switch i8 %38, label %42 [
i8 0, label %39
i8 35, label %39
]
39: ; preds = %33, %19, %37, %37, %25, %42
%40 = call i64 @fgets(i8* %3, i32 2049, i32* %4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %13
42: ; preds = %37
%43 = call i32 @add(i8* %30)
br label %39
44: ; preds = %39, %6
%45 = call i32 @fclose(i32* %4)
ret void
}