#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 uint8_t;
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
scalar_t__ pipe(int *);
scalar_t__ read(int, char *, size_t);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
uint8_t check_linux(void) {
  size_t size;
  ssize_t ssize;
  char buffer[7], *ptr;
  pid_t uname;
  int fds[2];
  if (pipe(fds))
    return 0;
  if ((uname = fork())) {
    close(fds[1]);
    size = sizeof(buffer);
    ptr = buffer;
    while (size) {
      ssize = read(fds[0], ptr, size);
      if (ssize <= 0)
        break;
      ptr += ssize;
      size -= ssize;
    }
    while (size--)
      *ptr++ = '\0';
    wait(NULL);
    close(fds[0]);
  } else {
    close(fds[0]);
    dup2(fds[1], STDOUT_FILENO);
    execlp("uname", "uname", "-s", NULL);
    exit(EXIT_FAILURE);
  }
  return !strcmp(buffer, "Linux\n");
}


x86 assembly (clang, -O0):
<check_linux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x34(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     11b7 <check_linux+0x27>
movl   $0x0,-0x4(%rbp)
jmp    12dd <check_linux+0x14d>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     127c <check_linux+0xec>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movq   $0x7,-0x10(%rbp)
lea    -0x1f(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1231 <check_linux+0xa1>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jg     1211 <check_linux+0x81>
jmp    1231 <check_linux+0xa1>
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11e2 <check_linux+0x52>
jmp    1236 <check_linux+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1266 <check_linux+0xd6>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
jmp    1236 <check_linux+0xa6>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
jmp    12bd <check_linux+0x12d>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
mov    -0x30(%rbp),%edi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xd64(%rip),%rsi
lea    0xd63(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1090 <execlp@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x1f(%rbp),%rdi
lea    0xd41(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_linux>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1224 <check_linux+0x94>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     122c <check_linux+0x9c>
lea    0x11(%rsp),%r14
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    $0x7,%ebx
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <read@plt>
test   %rax,%rax
jle    11ee <check_linux+0x5e>
add    %rax,%r14
sub    %rax,%rbx
jne    11d0 <check_linux+0x40>
jmp    11fb <check_linux+0x6b>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    $0x756e694c,%ecx
xor    0x11(%rsp),%ecx
mov    $0xa7875,%edx
xor    0x14(%rsp),%edx
xor    %eax,%eax
or     %ecx,%edx
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xdb2(%rip),%rdi
lea    0xdb1(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1090 <execlp@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [6 x i8] c"uname\00"
@.str.1 = [3 x i8] c"-s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"Linux\0A\00"
define i32 @check_linux() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [7 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 0, i32* %1
br label %69
12: ; preds = %0
%13 = call i32 (...) @fork()
store i32 %13, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %52
15: ; preds = %12
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
store i64 7, i64* %2
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
store i8* %19, i8** %5
br label %20
20: ; preds = %32, %15
%21 = load i64, i64* %2
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%25 = load i32, i32* %24
%26 = load i8*, i8** %5
%27 = load i64, i64* %2
%28 = call i64 @read(i32 %25, i8* %26, i64 %27)
store i64 %28, i64* %3
%29 = load i64, i64* %3
%30 = icmp sle i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %23
br label %39
32: ; preds = %23
%33 = load i64, i64* %3
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 %33
store i8* %35, i8** %5
%36 = load i64, i64* %3
%37 = load i64, i64* %2
%38 = sub i64 %37, %36
store i64 %38, i64* %2
br label %20
39: ; preds = %31, %20
br label %40
40: ; preds = %44, %39
%41 = load i64, i64* %2
%42 = add i64 %41, -1
store i64 %42, i64* %2
%43 = icmp ne i64 %41, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %5
store i8 0, i8* %45
br label %40
47: ; preds = %40
%48 = call i32 @wait(i32* null)
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
br label %63
52: ; preds = %12
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%57 = load i32, i32* %56
%58 = load i32, i32* @STDOUT_FILENO
%59 = call i32 @dup2(i32 %57, i32 %58)
%60 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %47
%64 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%65 = call i32 @strcmp(i8* %64, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
%67 = xor i1 %66, true
%68 = zext i1 %67 to i32
store i32 %68, i32* %1
br label %69
69: ; preds = %63, %11
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [6 x i8] c"uname\00"
@.str.1 = [3 x i8] c"-s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"Linux\0A\00"
define i32 @check_linux() {
%1 = alloca [7 x i8]
%2 = alloca [2 x i32]
%3 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %43
8: ; preds = %0
%9 = call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %33, label %11
11: ; preds = %8
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %11, %21
%16 = phi i8* [ %3, %11 ], [ %22, %21 ]
%17 = phi i64 [ 7, %11 ], [ %23, %21 ]
%18 = load i32, i32* %5
%19 = call i64 @read(i32 %18, i8* %16, i64 %17)
%20 = icmp slt i64 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %16, i64 %19
%23 = sub i64 %17, %19
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %15
25: ; preds = %15
br label %26
26: ; preds = %21, %25
%27 = call i32 @wait(i32* null)
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
%30 = call i32 @bcmp(i8* dereferenceable(7) %3, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 7)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
br label %43
33: ; preds = %8
%34 = load i32, i32* %5
%35 = call i32 @close(i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%37 = load i32, i32* %36
%38 = load i32, i32* @STDOUT_FILENO
%39 = call i32 @dup2(i32 %37, i32 %38)
%40 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %0, %26
%44 = phi i32 [ %32, %26 ], [ 0, %0 ]
ret i32 %44
}