#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
int fill_unread_mail(char *str, int n) {
  FILE *f = popen("notmuch count tag:inbox", "r");
  if (f == NULL) {
    fprintf(stderr, "Could not open the 'notmuch' command\n");
    exit(1);
  }
  int unread_mail;
  if (0 == fscanf(f, "%d", &unread_mail)) {
    pclose(f);
    fprintf(stderr, "Could not parse notmuch output\n");
    exit(1);
  }
  pclose(f);
  str[0] = unread_mail == 0 ? ' ' : 'M';
  return 1;
}


x86 assembly (clang, -O0):
<fill_unread_mail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a0 <fill_unread_mail+0x50>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ea <fill_unread_mail+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x1c(%rbp),%edx
mov    $0x4d,%eax
mov    $0x20,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_unread_mail>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe9d(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11bf <fill_unread_mail+0x6f>
mov    %rax,%rbx
lea    0xec2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <pclose@plt>
test   %r15,%r15
je     11d1 <fill_unread_mail+0x81>
cmpl   $0x0,0xc(%rsp)
mov    $0x20,%eax
mov    $0x4d,%ecx
cmove  %eax,%ecx
mov    %cl,(%r14)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
jmp    11e1 <fill_unread_mail+0x91>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"notmuch count tag:inbox\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Could not open the 'notmuch' command\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [32 x i8] c"Could not parse notmuch output\0A\00"
define i32 @fill_unread_mail(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = call i64 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%17 = icmp eq i64 0, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = call i32 @pclose(i32* %19)
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load i32*, i32** %5
%26 = call i32 @pclose(i32* %25)
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 32, i32 77
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 %31, i8* %33
ret i32 1
}

LLVM IR (-O2):
@.str = [24 x i8] c"notmuch count tag:inbox\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Could not open the 'notmuch' command\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [32 x i8] c"Could not parse notmuch output\0A\00"
define i32 @fill_unread_mail(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast i32* %3 to i8*
%12 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%13 = icmp eq i64 %12, 0
%14 = call i32 @pclose(i32* %4)
br i1 %13, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8 32, i8 77
store i8 %22, i8* %0
ret i32 1
}