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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int MAXPATHLEN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
char *sasutil_get_proc_name(int);
scalar_t__ sasutil_get_uint(char *, unsigned long *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
void sasutil_map_cmd(int argc, char *argv[]) {
  FILE *arq;
  char path[MAXPATHLEN];
  char line[512];
  int i;
  for (i = 0; i < argc; ++i) {
    pid_t pid;
    unsigned long uintpid;
    if (sasutil_get_uint(argv[i], &uintpid, 10)) {
      fprintf(stderr, "  Error: invalid argument: %s\n", optarg);
      exit(EXIT_FAILURE);
    }
    pid = uintpid;
    printf("Displaying memory maps for PID %d (%s)\n", (int)pid,
           sasutil_get_proc_name(pid));
    snprintf(path, MAXPATHLEN, "/proc/%d/maps", pid);
    arq = fopen(path, "r");
    if (!arq) {
      fprintf(stderr, "  Error: could not open %s map file\n", path);
      exit(0);
    }
    while (fgets(line, 512, arq)) {
      printf("%s", line);
    }
  }
}


x86 assembly (clang, -O0):
<sasutil_map_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x248(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x234(%rbp)
mov    -0x234(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    132a <sasutil_map_cmd+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x234(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x240(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <sasutil_get_uint@plt>
cmp    $0x0,%rax
je     1231 <sasutil_map_cmd+0xb1>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%rdx
lea    0xde2(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x240(%rbp),%rax
mov    %eax,-0x238(%rbp)
mov    -0x238(%rbp),%eax
mov    %eax,-0x24c(%rbp)
mov    -0x238(%rbp),%edi
call   1050 <sasutil_get_proc_name@plt>
mov    -0x24c(%rbp),%esi
mov    %rax,%rdx
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x248(%rbp),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
mov    -0x238(%rbp),%ecx
lea    0xdbe(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x248(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d3 <sasutil_map_cmd+0x153>
mov    -0x248(%rbp),%rdx
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    12d8 <sasutil_map_cmd+0x158>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1311 <sasutil_map_cmd+0x191>
lea    -0x230(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d8 <sasutil_map_cmd+0x158>
jmp    1316 <sasutil_map_cmd+0x196>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11cb <sasutil_map_cmd+0x4b>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sasutil_map_cmd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,-0x40(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
test   %edi,%edi
jle    1288 <sasutil_map_cmd+0x108>
mov    %edi,%eax
mov    %rax,-0x38(%rbp)
lea    -0x250(%rbp),%r12
lea    0xeaa(%rip),%r13
xor    %r14d,%r14d
mov    -0x30(%rbp),%rbx
jmp    11ee <sasutil_map_cmd+0x6e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    -0x38(%rbp),%r14
je     1288 <sasutil_map_cmd+0x108>
mov    -0x40(%rbp),%rax
mov    (%rax,%r14,8),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <sasutil_get_uint@plt>
test   %rax,%rax
jne    1297 <sasutil_map_cmd+0x117>
mov    -0x48(%rbp),%r15d
mov    %r15d,%edi
call   1050 <sasutil_get_proc_name@plt>
lea    0xdff(%rip),%rdi
mov    %r15d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
lea    0xe07(%rip),%rdx
mov    %r15d,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
lea    0xe03(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12c4 <sasutil_map_cmd+0x144>
mov    %rax,%r15
nop
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e0 <sasutil_map_cmd+0x60>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1260 <sasutil_map_cmd+0xe0>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%rdx
lea    0xd4f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c" Error: invalid argument: %s\0A\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@.str.1 = [40 x i8] c"Displaying memory maps for PID %d (%s)\0A\00"
@.str.2 = [14 x i8] c"/proc/%d/maps\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c" Error: could not open %s map file\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @sasutil_map_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i32, i32* @MAXPATHLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
store i32 0, i32* %9
br label %16
16: ; preds = %61, %2
%17 = load i32, i32* %9
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %64
20: ; preds = %16
%21 = load i8**, i8*** %4
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i64 @sasutil_get_uint(i8* %25, i64* %11, i32 10)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** @optarg
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %20
%35 = load i64, i64* %11
%36 = trunc i64 %35 to i32
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = load i32, i32* %10
%39 = call i8* @sasutil_get_proc_name(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %39)
%41 = load i32, i32* @MAXPATHLEN
%42 = load i32, i32* %10
%43 = call i32 @snprintf(i8* %15, i32 %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %44, i32** %5
%45 = load i32*, i32** %5
%46 = icmp ne i32* %45, null
br i1 %46, label %51, label %47
47: ; preds = %34
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %34
br label %52
52: ; preds = %57, %51
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%54 = load i32*, i32** %5
%55 = call i64 @fgets(i8* %53, i32 512, i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %58)
br label %52
60: ; preds = %52
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %16
64: ; preds = %16
%65 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c" Error: invalid argument: %s\0A\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@.str.1 = [40 x i8] c"Displaying memory maps for PID %d (%s)\0A\00"
@.str.2 = [14 x i8] c"/proc/%d/maps\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c" Error: could not open %s map file\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @sasutil_map_cmd(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca i64
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %48
10: ; preds = %2
%11 = bitcast i64* %4 to i8*
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %10, %45
%14 = phi i64 [ 0, %10 ], [ %46, %45 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = call i64 @sasutil_get_uint(i8* %16, i64* %4, i32 10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** @optarg
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
%26 = load i64, i64* %4
%27 = trunc i64 %26 to i32
%28 = call i8* @sasutil_get_proc_name(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %28)
%30 = load i32, i32* @MAXPATHLEN
%31 = call i32 @snprintf(i8* %7, i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%32 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %25
%35 = call i64 @fgets(i8* %8, i32 512, i32* %32)
%36 = icmp eq i64 %35, 0
br i1 %36, label %45, label %41
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %34, %41
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%43 = call i64 @fgets(i8* %8, i32 512, i32* %32)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %41
45: ; preds = %41, %34
%46 = add nuw nsw i64 %14, 1
%47 = icmp eq i64 %46, %12
br i1 %47, label %48, label %13
48: ; preds = %45, %2
ret void
}