#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__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int test_git() {
  FILE *gitpipe;
  char line[1024];
  if (!(gitpipe = popen("git --version 2>&1", "r"))) {
    printf("Error opening git command");
    return 0;
  }
  while (fgets(line, 1024, gitpipe))
    ;
  if (pclose(gitpipe) == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<test_git>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    0xeae(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1184 <test_git+0x44>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <test_git+0x93>
jmp    1189 <test_git+0x49>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ad <test_git+0x6d>
jmp    1189 <test_git+0x49>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
cmp    $0x0,%rax
jne    11cc <test_git+0x8c>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <test_git+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_git>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xeaf(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     119a <test_git+0x5a>
mov    %rax,%rbx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1170 <test_git+0x30>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11a8 <test_git+0x68>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"git --version 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Error opening git command\00"
define i32 @test_git() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 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 = icmp ne i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %21
8: ; preds = %0
br label %9
9: ; preds = %14, %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %9
15: ; preds = %9
%16 = load i32*, i32** %2
%17 = call i64 @pclose(i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %1
br label %21
20: ; preds = %15
store i32 0, i32* %1
br label %21
21: ; preds = %20, %19, %6
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [19 x i8] c"git --version 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Error opening git command\00"
define i32 @test_git() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 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 %7
5: ; preds = %0
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %14
7: ; preds = %0, %7
%8 = call i64 @fgets(i8* %2, i32 1024, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %7
10: ; preds = %7
%11 = call i64 @pclose(i32* %3)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %5
%15 = phi i32 [ 0, %5 ], [ %13, %10 ]
ret i32 %15
}