#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*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void printFilePerms(void) {
  FILE *poutput = popen("ls -l "
                        "umask-example.temp",
                        "r");
  char buff[512];
  while (fgets(buff, sizeof(buff), poutput) != NULL) {
    printf("%s", buff);
  }
  pclose(poutput);
}


x86 assembly (clang, -O0):
<printFilePerms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
lea    0xeae(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1199 <printFilePerms+0x59>
lea    -0x210(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    1162 <printFilePerms+0x22>
mov    -0x8(%rbp),%rdi
call   1040 <pclose@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFilePerms>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
lea    0xead(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b0 <printFilePerms+0x70>
lea    0xe9d(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <printFilePerms+0x50>
mov    %r15,%rdi
call   1040 <pclose@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ls -l umask-example.temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define void @printFilePerms() {
%1 = alloca i32*
%2 = alloca [512 x i8]
%3 = call i32* @popen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
br label %4
4: ; preds = %9, %0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = load i32*, i32** %1
%7 = call i32* @fgets(i8* %5, i32 512, i32* %6)
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %4
12: ; preds = %4
%13 = load i32*, i32** %1
%14 = call i32 @pclose(i32* %13)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"ls -l umask-example.temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define void @printFilePerms() {
%1 = alloca [512 x i8]
%2 = tail call i32* @popen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 512, i32* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0, %6
%7 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = call i32* @fgets(i8* %3, i32 512, i32* %2)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %6
10: ; preds = %6, %0
%11 = call i32 @pclose(i32* %2)
ret void
}