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

/* Variables and functions */
int /*<<< orphan*/ drive_init(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
void drive_load() {
  uint32_t len;
  char line[1024];
  FILE *fp = fopen("niet-drive", "r");
  if (fp == NULL)
    return;
  while (fgets(line, 1024, fp)) {
    len = strlen(line);
    if (line[len - 1] == '\n')
      line[--len] = '\0';
    if (len)
      drive_init(line);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<drive_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1188 <drive_load+0x38>
jmp    1211 <drive_load+0xc1>
jmp    118d <drive_load+0x3d>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1205 <drive_load+0xb5>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11ea <drive_load+0x9a>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
cmpl   $0x0,-0x4(%rbp)
je     1200 <drive_load+0xb0>
lea    -0x410(%rbp),%rdi
call   1060 <drive_init@plt>
jmp    118d <drive_load+0x3d>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drive_load>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d7 <drive_load+0x87>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11cf <drive_load+0x7f>
mov    %rsp,%rbx
jmp    11a5 <drive_load+0x55>
nop
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11cf <drive_load+0x7f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
cmpb   $0xa,-0x1(%rsp,%rcx,1)
jne    11c1 <drive_load+0x71>
add    $0xffffffffffffffff,%rcx
movb   $0x0,(%rsp,%rcx,1)
mov    %ecx,%eax
test   %eax,%eax
je     1190 <drive_load+0x40>
mov    %rbx,%rdi
call   1060 <drive_init@plt>
jmp    1190 <drive_load+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"niet-drive\00"
@.str.1 = [2 x i8] c"r\00"
define void @drive_load() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
br label %39
8: ; preds = %0
br label %9
9: ; preds = %35, %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i32, i32* %1
%26 = add nsw i32 %25, -1
store i32 %26, i32* %1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %24, %14
%30 = load i32, i32* %1
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%34 = call i32 @drive_init(i8* %33)
br label %35
35: ; preds = %32, %29
br label %9
36: ; preds = %9
%37 = load i32*, i32** %3
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %7
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"niet-drive\00"
@.str.1 = [2 x i8] c"r\00"
define void @drive_load() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = call i64 @fgets(i8* %2, i32 1024, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %5, %21
%9 = call i32 @strlen(i8* %2)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %8
store i8 0, i8* %12
br label %16
16: ; preds = %15, %8
%17 = phi i32 [ %10, %15 ], [ %9, %8 ]
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @drive_init(i8* %2)
br label %21
21: ; preds = %19, %16
%22 = call i64 @fgets(i8* %2, i32 1024, i32* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %8
24: ; preds = %21, %5
%25 = call i32 @fclose(i32* %3)
br label %26
26: ; preds = %0, %24
ret void
}