#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 */
struct stat {
  scalar_t__ st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ chdir(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int size = 0;
  char fn[512];
  struct stat st;
  if (argc > 1 && chdir(argv[1]) < 0) {
    fprintf(stderr, "getdu: %s: %s.\n", argv[1], strerror(errno));
    return 1;
  }
  while (scanf("%*s %s", fn) == 1) {
    if (lstat(fn, &st))
      continue;
    if (S_ISREG(st.st_mode))
      size += st.st_size;
    size += 512;
  }
  printf("%.2f MB\n", size / 1048576.0 + 0.01);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1205 <main+0x95>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    1205 <main+0x95>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x238(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rdx
mov    %rax,%rcx
lea    0xe1c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <main+0x142>
jmp    120a <main+0x9a>
lea    -0x220(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    127e <main+0x10e>
lea    -0x220(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
je     1248 <main+0xd8>
jmp    120a <main+0x9a>
mov    -0x228(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%rax
je     126e <main+0xfe>
mov    -0x230(%rbp),%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    120a <main+0x9a>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xd7d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd69(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xd81(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
cmp    $0x2,%edi
jl     1197 <main+0x27>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
js     1215 <main+0xa5>
xor    %ebp,%ebp
lea    0xe80(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    11ed <main+0x7d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <lstat@plt>
test   %rax,%rax
jne    11b0 <main+0x40>
mov    0x8(%rsp),%edi
call   1070 <S_ISREG@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     11e3 <main+0x73>
mov    (%rsp),%ecx
add    %ecx,%ebp
add    $0x200,%ebp
jmp    11b0 <main+0x40>
cvtsi2sd %ebp,%xmm0
mulsd  0xe07(%rip),%xmm0
addsd  0xe07(%rip),%xmm0
cvttsd2si %xmm0,%esi
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1249 <main+0xd9>
mov    0x2dc4(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd9(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"getdu: %s: %s.\0A\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"%*s %s\00"
@.str.2 = [9 x i8] c"%.2f MB\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @chdir(i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
store i32 1, i32* %3
br label %57
25: ; preds = %11, %2
br label %26
26: ; preds = %47, %34, %25
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%28 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %50
30: ; preds = %26
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%32 = call i64 @lstat(i8* %31, %struct.stat* %8)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %26
35: ; preds = %30
%36 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%37 = load i32, i32* %36
%38 = call i64 @S_ISREG(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %6
br label %47
47: ; preds = %40, %35
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 512
store i32 %49, i32* %6
br label %26
50: ; preds = %26
%51 = load i32, i32* %6
%52 = sitofp i32 %51 to double
%53 = fdiv double %52, 0x4130000000000000
%54 = fadd double %53, 1.000000e-02
%55 = fptosi double %54 to i32
%56 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %55)
store i32 0, i32* %3
br label %57
57: ; preds = %50, %17
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"getdu: %s: %s.\0A\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"%*s %s\00"
@.str.2 = [9 x i8] c"%.2f MB\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @chdir(i8* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17)
br label %45
19: ; preds = %8, %2
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %22
22: ; preds = %30, %19
%23 = phi i32 [ %38, %30 ], [ 0, %19 ]
br label %24
24: ; preds = %22, %27
%25 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = call i64 @lstat(i8* %5, %struct.stat* %4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %24
30: ; preds = %27
%31 = load i32, i32* %20
%32 = call i64 @S_ISREG(i32 %31)
%33 = icmp eq i64 %32, 0
%34 = load i64, i64* %21
%35 = trunc i64 %34 to i32
%36 = select i1 %33, i32 0, i32 %35
%37 = add i32 %23, 512
%38 = add i32 %37, %36
br label %22
39: ; preds = %24
%40 = sitofp i32 %23 to double
%41 = fmul double %40, 0x3EB0000000000000
%42 = fadd double %41, 1.000000e-02
%43 = fptosi double %42 to i32
%44 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %39, %13
%46 = phi i32 [ 1, %13 ], [ 0, %39 ]
ret i32 %46
}