#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *get_data_dir(int /*<<< orphan*/);
int /*<<< orphan*/ mvaddch(int, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int gplot(char *filename, int x_offset, int y_offset, int ign_space) {
  FILE *fp;
  int x, y;
  int c;
  char fname[128];
  snprintf(fname, sizeof fname, "%s%s", get_data_dir(0), filename);
  x = x_offset;
  y = y_offset;
  fp = fopen(fname, "r");
  if (fp == NULL) {
    return 1;
  }
  while ((c = fgetc(fp)) != EOF) {
    if (c == '\n') {
      y++;
      x = x_offset;
    } else {
      if (c == ' ' && ign_space == 1) {
      } else {
        mvaddch(y, x, c);
      }
      x++;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<gplot>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
xor    %edi,%edi
call   1080 <get_data_dir@plt>
mov    -0xc8(%rbp),%rdi
mov    %rax,%rcx
mov    -0x10(%rbp),%r8
mov    $0x80,%esi
lea    0xe59(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e6 <gplot+0x86>
movl   $0x1,-0x4(%rbp)
jmp    1269 <gplot+0x109>
jmp    11eb <gplot+0x8b>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%eax
je     1259 <gplot+0xf9>
cmpl   $0xa,-0x34(%rbp)
jne    1224 <gplot+0xc4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1254 <gplot+0xf4>
cmpl   $0x20,-0x34(%rbp)
jne    123d <gplot+0xdd>
cmpl   $0x1,-0x1c(%rbp)
jne    123d <gplot+0xdd>
jmp    124b <gplot+0xeb>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1070 <mvaddch@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11eb <gplot+0x8b>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gplot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %edi,%edi
call   1080 <get_data_dir@plt>
lea    0xe75(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %rax,%rcx
mov    %rbx,%r8
call   1040 <snprintf@plt>
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d9 <gplot+0x79>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e21(%rip),%r13
cmp    0x0(%r13),%eax
jne    11f0 <gplot+0x90>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11de <gplot+0x7e>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%ebp
jmp    1215 <gplot+0xb5>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12d
mov    %r15d,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%eax
je     11cd <gplot+0x6d>
cmp    $0xa,%eax
je     1200 <gplot+0xa0>
cmp    $0x1,%r14d
jne    1225 <gplot+0xc5>
cmp    $0x20,%eax
je     1231 <gplot+0xd1>
mov    %r12d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1070 <mvaddch@plt>
add    $0x1,%ebp
jmp    1207 <gplot+0xa7>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @gplot(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [128 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%16 = call i8* @get_data_dir(i32 0)
%17 = load i8*, i8** %6
%18 = call i32 @snprintf(i8* %15, i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i32, i32* %7
store i32 %19, i32* %11
%20 = load i32, i32* %8
store i32 %20, i32* %12
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %10
%23 = load i32*, i32** %10
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 1, i32* %5
br label %58
26: ; preds = %4
br label %27
27: ; preds = %54, %26
%28 = load i32*, i32** %10
%29 = call i32 @fgetc(i32* %28)
store i32 %29, i32* %13
%30 = load i32, i32* @EOF
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %55
32: ; preds = %27
%33 = load i32, i32* %13
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
%38 = load i32, i32* %7
store i32 %38, i32* %11
br label %54
39: ; preds = %32
%40 = load i32, i32* %13
%41 = icmp eq i32 %40, 32
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* %9
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %46
45: ; preds = %42
br label %51
46: ; preds = %42, %39
%47 = load i32, i32* %12
%48 = load i32, i32* %11
%49 = load i32, i32* %13
%50 = call i32 @mvaddch(i32 %47, i32 %48, i32 %49)
br label %51
51: ; preds = %46, %45
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %54
54: ; preds = %51, %35
br label %27
55: ; preds = %27
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %5
br label %58
58: ; preds = %55, %25
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @gplot(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = tail call i8* @get_data_dir(i32 0)
%8 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %0)
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %39, label %11
11: ; preds = %4
%12 = call i32 @fgetc(i32* %9)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %37, label %15
15: ; preds = %11
%16 = icmp eq i32 %3, 1
br label %17
17: ; preds = %15, %31
%18 = phi i32 [ %12, %15 ], [ %34, %31 ]
%19 = phi i32 [ %2, %15 ], [ %33, %31 ]
%20 = phi i32 [ %1, %15 ], [ %32, %31 ]
%21 = icmp eq i32 %18, 10
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = add nsw i32 %19, 1
br label %31
24: ; preds = %17
%25 = icmp eq i32 %18, 32
%26 = and i1 %16, %25
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @mvaddch(i32 %19, i32 %20, i32 %18)
br label %29
29: ; preds = %24, %27
%30 = add nsw i32 %20, 1
br label %31
31: ; preds = %29, %22
%32 = phi i32 [ %1, %22 ], [ %30, %29 ]
%33 = phi i32 [ %23, %22 ], [ %19, %29 ]
%34 = call i32 @fgetc(i32* %9)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %17
37: ; preds = %31, %11
%38 = call i32 @fclose(i32* %9)
br label %39
39: ; preds = %4, %37
%40 = phi i32 [ 0, %37 ], [ 1, %4 ]
ret i32 %40
}