#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*/ column(char *, int, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strtol(char *, char **, int);
long int get_needed_megabytes(char *output_directory, char *latest_date) {
  char sys_string[1024];
  long int needed_megabytes = 0;
  char input_buffer[512];
  char megabytes_string[64];
  FILE *input_pipe;
  sprintf(sys_string, "ls -l --block-size=M %s/*%s*", output_directory,
          latest_date);
  input_pipe = popen(sys_string, "r");
  while (get_line(input_buffer, input_pipe)) {
    column(megabytes_string, 4, input_buffer);
    needed_megabytes += strtol(megabytes_string, (char **)0, 10);
  }
  pclose(input_pipe);
  return needed_megabytes;
}


x86 assembly (clang, -O0):
<get_needed_megabytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x670,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe6c(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x668(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x668(%rbp),%rsi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1210 <get_needed_megabytes+0xb0>
lea    -0x660(%rbp),%rdi
lea    -0x620(%rbp),%rdx
mov    $0x4,%esi
call   1060 <column@plt>
lea    -0x660(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
add    -0x418(%rbp),%rax
mov    %rax,-0x418(%rbp)
jmp    11b3 <get_needed_megabytes+0x53>
mov    -0x668(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x418(%rbp),%rax
add    $0x670,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_needed_megabytes>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x648,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe85(%rip),%rsi
lea    0x240(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
mov    %rax,%r14
lea    0x40(%rsp),%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11f2 <get_needed_megabytes+0x92>
mov    %rsp,%r15
lea    0x40(%rsp),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x4,%esi
mov    %r12,%rdx
call   1060 <column@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
add    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11c0 <get_needed_megabytes+0x60>
mov    %r14,%rdi
call   1040 <pclose@plt>
mov    %rbx,%rax
add    $0x648,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"ls -l --block-size=M %s/*%s*\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_needed_megabytes(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i64
%7 = alloca [512 x i8]
%8 = alloca [64 x i8]
%9 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %6
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
br label %16
16: ; preds = %21, %2
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %9
%19 = call i64 @get_line(i8* %17, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%24 = call i32 @column(i8* %22, i32 4, i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%26 = call i64 @strtol(i8* %25, i8** null, i32 10)
%27 = load i64, i64* %6
%28 = add nsw i64 %27, %26
store i64 %28, i64* %6
br label %16
29: ; preds = %16
%30 = load i32*, i32** %9
%31 = call i32 @pclose(i32* %30)
%32 = load i64, i64* %6
ret i64 %32
}

LLVM IR (-O2):
@.str = [29 x i8] c"ls -l --block-size=M %s/*%s*\00"
@.str.1 = [2 x i8] c"r\00"
define i64 @get_needed_megabytes(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [512 x i8]
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i64 @get_line(i8* %7, i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %2, %13
%14 = phi i64 [ %17, %13 ], [ 0, %2 ]
%15 = call i32 @column(i8* %8, i32 4, i8* %7)
%16 = call i64 @strtol(i8* nocapture %8, i8** null, i32 10)
%17 = add nsw i64 %16, %14
%18 = call i64 @get_line(i8* %7, i32* %10)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %13
20: ; preds = %13, %2
%21 = phi i64 [ 0, %2 ], [ %17, %13 ]
%22 = call i32 @pclose(i32* %10)
ret i64 %21
}