#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 */
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ *strstr(char *, char *);
char checkDistro() {
  FILE *fp;
  char name[255], id = '0';
  errno = 0;
  if ((fp = fopen("/proc/version", "r")) == NULL) {
    fprintf(stderr,
            "Error opening file \"%s\", there may be misbehavior: %s.\n",
            "/proc/version", strerror(errno));
    return id;
  }
  if (fgets(name, 255 - 1, fp) == NULL) {
    fprintf(stderr, "File \"%s\" corrupted!\n", "/proc/version");
    return id;
  }
  fclose(fp);
  if (strstr(name, "Ubuntu") != NULL || strstr(name, "Debian") != NULL) {
    id = 'u';
  } else if (strstr(name, "fedora") != NULL || strstr(name, "SUSE") != NULL) {
    id = 'y';
  } else if (strstr(name, "ARCH") != NULL) {
    id = 'a';
  } else {
    fprintf(stderr, "\nDistribution not supported:\n%s\n", name);
  }
  return id;
}


x86 assembly (clang, -O0):
<checkDistro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movb   $0x30,-0x111(%rbp)
mov    0x2e5f(%rip),%rax
movq   $0x0,(%rax)
lea    0xe79(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11eb <checkDistro+0x8b>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x118(%rbp),%edi
mov    %rax,%rcx
lea    0xe41(%rip),%rsi
lea    0xe2a(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x111(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1325 <checkDistro+0x1c5>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xfe,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1236 <checkDistro+0xd6>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
lea    0xddf(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x111(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1325 <checkDistro+0x1c5>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x110(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    1279 <checkDistro+0x119>
lea    -0x110(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1285 <checkDistro+0x125>
movb   $0x75,-0x111(%rbp)
jmp    131c <checkDistro+0x1bc>
lea    -0x110(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    12bf <checkDistro+0x15f>
lea    -0x110(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12cb <checkDistro+0x16b>
movb   $0x79,-0x111(%rbp)
jmp    1317 <checkDistro+0x1b7>
lea    -0x110(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12f4 <checkDistro+0x194>
movb   $0x61,-0x111(%rbp)
jmp    1312 <checkDistro+0x1b2>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1317 <checkDistro+0x1b7>
jmp    131c <checkDistro+0x1bc>
mov    -0x111(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDistro>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    0x2e67(%rip),%r14
movq   $0x0,(%r14)
lea    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1243 <checkDistro+0xe3>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0xfe,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1270 <checkDistro+0x110>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe9f(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    $0x75,%bl
test   %rax,%rax
jne    1290 <checkDistro+0x130>
lea    0xe8c(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
jne    1290 <checkDistro+0x130>
lea    0xe7b(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    $0x79,%bl
test   %rax,%rax
jne    1290 <checkDistro+0x130>
lea    0xe68(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
jne    1290 <checkDistro+0x130>
lea    0xe59(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strstr@plt>
mov    $0x61,%bl
test   %rax,%rax
jne    1290 <checkDistro+0x130>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %rsp,%rdx
jmp    1287 <checkDistro+0x127>
mov    0x2d96(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   1070 <strerror@plt>
lea    0xdb5(%rip),%rsi
lea    0xd9e(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    128e <checkDistro+0x12e>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
lea    0xd79(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x30,%bl
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Error opening file \22%s\22, there may be misbehavior: %s.\0A\00"
@.str.3 = [22 x i8] c"File \22%s\22 corrupted!\0A\00"
@.str.4 = [7 x i8] c"Ubuntu\00"
@.str.5 = [7 x i8] c"Debian\00"
@.str.6 = [7 x i8] c"fedora\00"
@.str.7 = [5 x i8] c"SUSE\00"
@.str.8 = [5 x i8] c"ARCH\00"
@.str.9 = [33 x i8] c"\0ADistribution not supported:\0A%s\0A\00"
define signext i8 @checkDistro() {
%1 = alloca i8
%2 = alloca i32*
%3 = alloca [255 x i8]
%4 = alloca i8
store i8 48, i8* %4
store i64 0, i64* @errno
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i64, i64* @errno
%10 = call i8* @strerror(i64 %9)
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8, i8* %4
store i8 %12, i8* %1
br label %55
13: ; preds = %0
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i32* @fgets(i8* %14, i32 254, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = load i8, i8* %4
store i8 %21, i8* %1
br label %55
22: ; preds = %13
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%26 = call i32* @strstr(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp ne i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%30 = call i32* @strstr(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %28, %22
store i8 117, i8* %4
br label %53
33: ; preds = %28
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%35 = call i32* @strstr(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp ne i32* %35, null
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%39 = call i32* @strstr(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %42
41: ; preds = %37, %33
store i8 121, i8* %4
br label %52
42: ; preds = %37
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%44 = call i32* @strstr(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %47
46: ; preds = %42
store i8 97, i8* %4
br label %51
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %47, %46
br label %52
52: ; preds = %51, %41
br label %53
53: ; preds = %52, %32
%54 = load i8, i8* %4
store i8 %54, i8* %1
br label %55
55: ; preds = %53, %18, %7
%56 = load i8, i8* %1
ret i8 %56
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Error opening file \22%s\22, there may be misbehavior: %s.\0A\00"
@.str.3 = [22 x i8] c"File \22%s\22 corrupted!\0A\00"
@.str.4 = [7 x i8] c"Ubuntu\00"
@.str.5 = [7 x i8] c"Debian\00"
@.str.6 = [7 x i8] c"fedora\00"
@.str.7 = [5 x i8] c"SUSE\00"
@.str.8 = [5 x i8] c"ARCH\00"
@.str.9 = [33 x i8] c"\0ADistribution not supported:\0A%s\0A\00"
define signext i8 @checkDistro() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
store i64 0, i64* @errno
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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 %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i64, i64* @errno
%8 = tail call i8* @strerror(i64 %7)
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %35
10: ; preds = %0
%11 = call i32* @fgets(i8* %2, i32 254, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %35
16: ; preds = %10
%17 = call i32 @fclose(i32* %3)
%18 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %2)
br label %35
35: ; preds = %32, %20, %16, %26, %23, %29, %13, %5
%36 = phi i8 [ 48, %5 ], [ 48, %13 ], [ 48, %32 ], [ 117, %20 ], [ 117, %16 ], [ 121, %26 ], [ 121, %23 ], [ 97, %29 ]
ret i8 %36
}