#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*/ err(int, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ warn(char *, char const *, int /*<<< orphan*/);
int exec_cmd(const char *cmd, FILE *fout) {
  char s[500];
  FILE *pcmd = popen(cmd, "r");
  if (pcmd == NULL)
    err(1, "cannot start git describe");
  fgets(s, 500, pcmd);
  if (s[strlen(s) - 1] == '\n')
    s[strlen(s) - 1] = 0;
  fputs(s, fout);
  int rc = pclose(pcmd);
  if (rc != 0)
    warn("cannot execute: %s. Error: %s", cmd, strerror(errno));
  return rc;
}


x86 assembly (clang, -O0):
<exec_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11c9 <exec_cmd+0x49>
mov    $0x1,%edi
lea    0xe3e(%rip),%rsi
call   1080 <err@plt>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x1f4,%esi
call   1070 <fgets@plt>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    121c <exec_cmd+0x9c>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x218(%rbp),%rdi
call   1050 <pclose@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
je     1279 <exec_cmd+0xf9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
lea    0xda8(%rip),%rdi
call   1030 <warn@plt>
mov    -0x21c(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_cmd>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1f8,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe65(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b9 <exec_cmd+0x39>
lea    0xe53(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r12,1)
jne    11ee <exec_cmd+0x6e>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1226 <exec_cmd+0xa6>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe00(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <warn@plt>
mov    %ebx,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"cannot start git describe\00"
@.str.2 = [30 x i8] c"cannot execute: %s. Error: %s\00"
@errno = global i32 0
define i32 @exec_cmd(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [500 x i8]
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32 @fgets(i8* %15, i32 500, i32* %16)
%18 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %32
26: ; preds = %14
%27 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %26, %14
%33 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%34 = load i32*, i32** %4
%35 = call i32 @fputs(i8* %33, i32* %34)
%36 = load i32*, i32** %6
%37 = call i32 @pclose(i32* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %32
%41 = load i8*, i8** %3
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %43)
br label %45
45: ; preds = %40, %32
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"cannot start git describe\00"
@.str.2 = [30 x i8] c"cannot execute: %s. Error: %s\00"
@errno = global i32 0
define i32 @exec_cmd(i8* %0, i32* nocapture %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = call i32 @fgets(i8* %4, i32 500, i32* %5)
%11 = call i32 @strlen(i8* %4)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = call i32 @strlen(i8* %4)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %17, %9
%23 = call i32 @fputs(i8* %4, i32* %1)
%24 = call i32 @pclose(i32* %5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %28)
br label %30
30: ; preds = %26, %22
ret i32 %24
}