#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 fbdev {
  int dummy;
};
struct city {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ decode_line(struct city *, char *);
int /*<<< orphan*/ draw_city(struct fbdev *, struct city *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct city *init_city(char *, int, char *);
struct fbdev *init_fb();
int /*<<< orphan*/ printf(char *, ...);
void parse_cm_file(char *filename) {
  struct city *the_city;
  printf("Initializing the city...\n");
  the_city = init_city("Ferrara", 1000, filename);
  printf("Parsing the file\n");
  char buff[81];
  FILE *fd = fopen(filename, "r");
  if (fd == NULL) {
    printf("Cannot open file %s\n", filename);
    abort();
  }
  while (fgets(buff, 80, fd) != NULL) {
    decode_line(the_city, buff);
  }
  struct fbdev *fb = init_fb();
  draw_city(fb, the_city);
  close(fd);
}


x86 assembly (clang, -O0):
<parse_cm_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdx
lea    0xe62(%rip),%rdi
mov    $0x3e8,%esi
call   1070 <init_city@plt>
mov    %rax,-0x10(%rbp)
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    120c <parse_cm_file+0x7c>
mov    -0x8(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1211 <parse_cm_file+0x81>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     123f <parse_cm_file+0xaf>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10b0 <decode_line@plt>
jmp    1211 <parse_cm_file+0x81>
mov    $0x0,%al
call   1080 <init_fb@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <draw_city@plt>
mov    -0x78(%rbp),%rdi
call   1050 <close@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cm_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r15
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3f(%rip),%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1080 <init_city@plt>
mov    %rax,%r14
lea    0xe60(%rip),%rdi
call   1040 <puts@plt>
lea    0xe24(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1256 <parse_cm_file+0xb6>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1230 <parse_cm_file+0x90>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <decode_line@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1210 <parse_cm_file+0x70>
xor    %eax,%eax
call   1090 <init_fb@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   10a0 <draw_city@plt>
mov    %r12,%rdi
call   1060 <close@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdad(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.city = type { i32 }
%struct.fbdev = type { i32 }
@.str = [26 x i8] c"Initializing the city...\0A\00"
@.str.1 = [8 x i8] c"Ferrara\00"
@.str.2 = [18 x i8] c"Parsing the file\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [21 x i8] c"Cannot open file %s\0A\00"
define void @parse_cm_file(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.city*
%4 = alloca [81 x i8]
%5 = alloca i32*
%6 = alloca %struct.fbdev*
store i8* %0, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call %struct.city* @init_city(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, i8* %8)
store %struct.city* %9, %struct.city** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %1
br label %20
20: ; preds = %25, %19
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32* @fgets(i8* %21, i32 80, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load %struct.city*, %struct.city** %3
%27 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%28 = call i32 @decode_line(%struct.city* %26, i8* %27)
br label %20
29: ; preds = %20
%30 = call %struct.fbdev* (...) @init_fb()
store %struct.fbdev* %30, %struct.fbdev** %6
%31 = load %struct.fbdev*, %struct.fbdev** %6
%32 = load %struct.city*, %struct.city** %3
%33 = call i32 @draw_city(%struct.fbdev* %31, %struct.city* %32)
%34 = load i32*, i32** %5
%35 = call i32 @close(i32* %34)
ret void
}

LLVM IR (-O2):
%struct.city = type { i32 }
%struct.fbdev = type { i32 }
@.str.1 = [8 x i8] c"Ferrara\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [21 x i8] c"Cannot open file %s\0A\00"
@str = [25 x i8] c"Initializing the city...\00"
@str.5 = [17 x i8] c"Parsing the file\00"
define void @parse_cm_file(i8* %0) {
%2 = alloca [81 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call %struct.city* @init_city(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1000, i8* %0)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%6 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32* @fgets(i8* %6, i32 80, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %19, label %15
12: ; preds = %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %9, %15
%16 = call i32 @decode_line(%struct.city* %4, i8* %6)
%17 = call i32* @fgets(i8* %6, i32 80, i32* %7)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %15
19: ; preds = %15, %9
%20 = call %struct.fbdev* (...) @init_fb()
%21 = call i32 @draw_city(%struct.fbdev* %20, %struct.city* %4)
%22 = call i32 @close(i32* %7)
ret void
}