#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 EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  FILE *inputStream;
  inputStream = popen("uname -a", "r");
  if (!inputStream) {
    perror("Sorry - cannot open uname");
    exit(-1);
  }
  char strBuffer[65];
  fscanf(inputStream, "%*s %*s %64s", strBuffer);
  pclose(inputStream);
  printf("Kernel version: %s\n", strBuffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <main+0x47>
lea    0xe73(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x60(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe92(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11bf <main+0x5f>
mov    %rax,%rbx
lea    0xe9c(%rip),%rsi
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0xe8c(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe45(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Sorry - cannot open uname\00"
@.str.3 = [13 x i8] c"%*s %*s %64s\00"
@.str.4 = [20 x i8] c"Kernel version: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [65 x i8]
store i32 0, i32* %1
%4 = call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 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** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%13 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %2
%15 = call i32 @pclose(i32* %14)
%16 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}

LLVM IR (-O2):
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Sorry - cannot open uname\00"
@.str.3 = [13 x i8] c"%*s %*s %64s\00"
@.str.4 = [20 x i8] c"Kernel version: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [65 x i8]
%2 = tail call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = getelementptr inbounds [65 x i8], [65 x i8]* %1, i64 0, i64 0
%9 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%10 = call i32 @pclose(i32* %2)
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%12 = load i32, i32* @EXIT_SUCCESS
ret i32 %12
}