#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 */

/* Variables and functions */
scalar_t__ fgets_with_openclose(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void print_usage(int pid, long base, long top) {
  char fname[256], cmdline[256];
  printf("0x%08lx-0x%08lx : ", base, top);
  if (pid == 0) {
    printf("----\n");
  } else {
    sprintf(fname, "/proc/%d/cmdline", pid);
    if (fgets_with_openclose(fname, cmdline, 256) < 0) {
      printf("%d\n", pid);
    } else {
      printf("%d %s\n", pid, cmdline);
    }
  }
}


x86 assembly (clang, -O0):
<print_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1179 <print_usage+0x49>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e4 <print_usage+0xb4>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8f(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x100,%edx
call   1030 <fgets_with_openclose@plt>
cmp    $0x0,%rax
jge    11c7 <print_usage+0x97>
mov    -0x4(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11df <print_usage+0xaf>
mov    -0x4(%rbp),%esi
lea    -0x220(%rbp),%rdx
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e4 <print_usage+0xb4>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_usage>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%ebx
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
je     11a1 <print_usage+0x61>
lea    0xeae(%rip),%rsi
lea    0x100(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   1040 <fgets_with_openclose@plt>
test   %rax,%rax
js     11b7 <print_usage+0x77>
lea    0xe95(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c7 <print_usage+0x87>
lea    0xe87(%rip),%rdi
add    $0x208,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>
lea    0xe66(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"0x%08lx-0x%08lx : \00"
@.str.1 = [6 x i8] c"----\0A\00"
@.str.2 = [17 x i8] c"/proc/%d/cmdline\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%d %s\0A\00"
define void @print_usage(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %9, i64 %10)
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %32
16: ; preds = %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i64 @fgets_with_openclose(i8* %20, i8* %21, i32 256)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %31
27: ; preds = %16
%28 = load i32, i32* %4
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %28, i8* %29)
br label %31
31: ; preds = %27, %24
br label %32
32: ; preds = %31, %14
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"0x%08lx-0x%08lx : \00"
@.str.2 = [17 x i8] c"/proc/%d/cmdline\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%d %s\0A\00"
@str = [5 x i8] c"----\00"
define void @print_usage(i32 %0, i64 %1, i64 %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %1, i64 %2)
%9 = icmp eq i32 %0, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %20
12: ; preds = %3
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%14 = call i64 @fgets_with_openclose(i8* %6, i8* %7, i32 256)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %20
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %0, i8* %7)
br label %20
20: ; preds = %16, %18, %10
ret void
}