#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setenv(char *, char *, int);
int main(void) {
  int i, r = 1;
  char var[] = "MYVAR";
  char temp[51];
  setenv(var, "test.txt", 1);
  if ((getenv(var)) == NULL)
    printf("variabele bestaat niet\n");
  else {
    FILE *fp;
    fp = fopen((getenv(var)), "r");
    while (!feof(fp)) {
      fgets(temp, 50, fp);
      if (feof(fp))
        break;
      printf("%d %s", r, temp);
      temp[0] = '\0';
      r++;
    }
    fclose(fp);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0xe64(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xe5e(%rip),%ax
mov    %ax,-0xe(%rbp)
lea    -0x12(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    -0x12(%rbp),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    11e5 <main+0x65>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    127a <main+0xfa>
lea    -0x12(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe2f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1220 <main+0xa0>
jmp    1271 <main+0xf1>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x32,%esi
call   1070 <fgets@plt>
mov    -0x58(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     124a <main+0xca>
jmp    1271 <main+0xf1>
mov    -0xc(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0x0,-0x50(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1201 <main+0x81>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movw   $0x52,0xc(%rsp)
movl   $0x4156594d,0x8(%rsp)
41
lea    0xe56(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11e2 <main+0x52>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xe26(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    1261 <main+0xd1>
mov    $0x1,%ebp
lea    0x10(%rsp),%r14
lea    0xdff(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x32,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    1261 <main+0xd1>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
movb   $0x0,0x10(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1220 <main+0x90>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.var = [6 x i8] c"MYVAR\00"
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [24 x i8] c"variabele bestaat niet\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%d %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
%5 = alloca [51 x i8]
%6 = alloca i32*
store i32 0, i32* %1
store i32 1, i32* %3
%7 = bitcast [6 x i8]* %4 to i8*
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = call i32 @setenv(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%11 = call i32* @getenv(i8* %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %42
15: ; preds = %0
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%17 = call i32* @getenv(i8* %16)
%18 = call i32* @fopen(i32* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
br label %19
19: ; preds = %32, %15
%20 = load i32*, i32** %6
%21 = call i64 @feof(i32* %20)
%22 = icmp ne i64 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32 @fgets(i8* %25, i32 50, i32* %26)
%28 = load i32*, i32** %6
%29 = call i64 @feof(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
br label %39
32: ; preds = %24
%33 = load i32, i32* %3
%34 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %33, i8* %34)
%36 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
store i8 0, i8* %36
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %19
39: ; preds = %31, %19
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39, %13
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.var = [6 x i8] c"MYVAR\00"
@.str = [9 x i8] c"test.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%d %s\00"
@str = [23 x i8] c"variabele bestaat niet\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = alloca [51 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [51 x i8], [51 x i8]* %2, i64 0, i64 0
%5 = call i32 @setenv(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
%6 = call i32* @getenv(i8* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %26
10: ; preds = %0
%11 = call i32* @fopen(i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = call i64 @feof(i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %10, %19
%15 = phi i32 [ %21, %19 ], [ 1, %10 ]
%16 = call i32 @fgets(i8* %4, i32 50, i32* %11)
%17 = call i64 @feof(i32* %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %15, i8* %4)
store i8 0, i8* %4
%21 = add nuw nsw i32 %15, 1
%22 = call i64 @feof(i32* %11)
%23 = icmp eq i64 %22, 0
br i1 %23, label %14, label %24
24: ; preds = %19, %14, %10
%25 = call i32 @fclose(i32* %11)
br label %26
26: ; preds = %24, %8
%27 = call i32 @exit(i32 0)
unreachable
}