#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void get_os(char *buffer, size_t size) {
  FILE *release;
  const char **pp;
  const char *release_files[] = {"/etc/redhat-release", "/etc/fedora-release",
                                 "/etc/mandriva-release", "/etc/SuSE-release",
                                 NULL};
  for (pp = release_files; *pp; pp++) {
    char *eol;
    release = fopen(*pp, "r");
    if (release == NULL)
      continue;
    if (fgets(buffer, size, release) == NULL)
      break;
    eol = strchr(buffer, '\n');
    if (eol)
      *eol = '\0';
    fclose(release);
    return;
  }
  strcpy(buffer, "unknown GNU/Linux");
}


x86 assembly (clang, -O0):
<get_os>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xe79(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     124c <get_os+0xec>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e9 <get_os+0x89>
jmp    123b <get_os+0xdb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1209 <get_os+0xa9>
jmp    124c <get_os+0xec>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     122d <get_os+0xcd>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    125c <get_os+0xfc>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11b4 <get_os+0x54>
mov    -0x8(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_os>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,0x20(%rsp)
lea    0xe8d(%rip),%rdi
mov    %rdi,(%rsp)
lea    0x8(%rsp),%rbx
lea    0xe91(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe99(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xea3(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xea9(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11cb <get_os+0x7b>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    11b0 <get_os+0x60>
jmp    120b <get_os+0xbb>
mov    %rax,%r13
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120b <get_os+0xbb>
mov    %r15,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11f6 <get_os+0xa6>
movb   $0x0,(%rax)
mov    %r13,%rdi
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe40(%rip),%rsi
mov    %r15,%rdi
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/etc/redhat-release\00"
@.str.1 = [20 x i8] c"/etc/fedora-release\00"
@.str.2 = [22 x i8] c"/etc/mandriva-release\00"
@.str.3 = [18 x i8] c"/etc/SuSE-release\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"unknown GNU/Linux\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca [5 x i8*]
%8 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = bitcast [5 x i8*]* %7 to i8*
%10 = bitcast i8* %9 to [5 x i8*]*
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i32 0, i32 0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i32 0, i32 1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i32 0, i32 2
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i32 0, i32 3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 0
store i8** %15, i8*** %6
br label %16
16: ; preds = %44, %2
%17 = load i8**, i8*** %6
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %23, i32** %5
%24 = load i32*, i32** %5
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %20
br label %44
27: ; preds = %20
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = load i32*, i32** %5
%31 = call i32* @fgets(i8* %28, i64 %29, i32* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %27
br label %47
34: ; preds = %27
%35 = load i8*, i8** %3
%36 = call i8* @strchr(i8* %35, i8 signext 10)
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i8*, i8** %8
store i8 0, i8* %40
br label %41
41: ; preds = %39, %34
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
br label %50
44: ; preds = %26
%45 = load i8**, i8*** %6
%46 = getelementptr inbounds i8*, i8** %45, i32 1
store i8** %46, i8*** %6
br label %16
47: ; preds = %33, %16
%48 = load i8*, i8** %3
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %47, %41
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"/etc/redhat-release\00"
@.str.1 = [20 x i8] c"/etc/fedora-release\00"
@.str.2 = [22 x i8] c"/etc/mandriva-release\00"
@.str.3 = [18 x i8] c"/etc/SuSE-release\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"unknown GNU/Linux\00"
define void @get_os(i8* %0, i64 %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
%6 = bitcast i8** %5 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %10
br label %14
11: ; preds = %14
%12 = load i8*, i8** %19
%13 = icmp eq i8* %12, null
br i1 %13, label %29, label %14
14: ; preds = %2, %11
%15 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = phi i8** [ %19, %11 ], [ %7, %2 ]
%17 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
%19 = getelementptr inbounds i8*, i8** %16, i64 1
br i1 %18, label %11, label %20
20: ; preds = %14
%21 = tail call i32* @fgets(i8* %0, i64 %1, i32* %17)
%22 = icmp eq i32* %21, null
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%25 = icmp eq i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store i8 0, i8* %24
br label %27
27: ; preds = %23, %26
%28 = tail call i32 @fclose(i32* %17)
br label %31
29: ; preds = %11, %20
%30 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %27, %29
ret void
}