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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strchr(char *, char);
int strlen(char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  char line[4096];
  FILE *file;
  if (argc != 1)
    print_usage("lsmod");
  file = fopen("/proc/modules", "r");
  if (!file) {
    perror("Opening /proc/modules");
    exit(1);
  }
  printf("Module                  Size  Used by\n");
  while (fgets(line, sizeof(line), file)) {
    char *tok;
    tok = strtok(line, " \t");
    printf("%-19s", tok);
    tok = strtok(NULL, " \t\n");
    printf(" %8s", tok);
    tok = strtok(NULL, " \t\n");
    if (tok) {
      printf("  %s", tok);
      tok = strtok(NULL, "\n");
      if (!tok)
        tok = "";
      else if (strchr(tok, ',')) {
        tok = strtok(tok, "\t ");
        if (tok[strlen(tok) - 1] == ',')
          tok[strlen(tok) - 1] = '\0';
      } else if (tok[0] == '-' && (tok[1] == '\0' || isspace(tok[1])))
        tok = "";
      printf(" %s", tok);
    }
    printf("\n");
  }
  fclose(file);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11df <main+0x2f>
lea    0xe26(%rip),%rdi
call   10d0 <print_usage@plt>
lea    0xe2a(%rip),%rdi
lea    0xe19(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    121d <main+0x6d>
lea    0xdfa(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rdx
mov    $0x1000,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1438 <main+0x288>
lea    -0x1010(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc7(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9b(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
je     1425 <main+0x275>
mov    -0x1020(%rbp),%rsi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd63(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
jne    131a <main+0x16a>
lea    0xd39(%rip),%rax
mov    %rax,-0x1020(%rbp)
jmp    1410 <main+0x260>
mov    -0x1020(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     13b7 <main+0x207>
mov    -0x1020(%rbp),%rdi
lea    0xd19(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x1020(%rbp)
mov    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1028(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    13b2 <main+0x202>
mov    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1030(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    140b <main+0x25b>
mov    -0x1020(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1406 <main+0x256>
mov    -0x1020(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     13f8 <main+0x248>
mov    -0x1020(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     1406 <main+0x256>
lea    0xc48(%rip),%rax
mov    %rax,-0x1020(%rbp)
jmp    140b <main+0x25b>
jmp    1410 <main+0x260>
mov    -0x1020(%rbp),%rsi
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    122b <main+0x7b>
mov    -0x1018(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
cmp    $0x1,%edi
je     11f2 <main+0x22>
lea    0xe13(%rip),%rdi
call   10f0 <print_usage@plt>
lea    0xe17(%rip),%rdi
lea    0xe06(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    1220 <main+0x50>
lea    0xdf7(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rax,%r15
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1253 <main+0x83>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    %rsp,%r13
lea    0xdca(%rip),%rbx
lea    0xdc7(%rip),%rbp
jmp    12a0 <main+0xd0>
mov    %r12,%r14
nopl   0x0(%rax)
lea    0xdba(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1244 <main+0x74>
mov    %r13,%rdi
lea    0xd74(%rip),%rsi
call   10d0 <strtok@plt>
lea    0xd6b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10d0 <strtok@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10d0 <strtok@plt>
test   %rax,%rax
je     1281 <main+0xb1>
lea    0xd43(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
lea    0xd29(%rip),%rsi
call   10d0 <strtok@plt>
lea    0xd14(%rip),%r14
test   %rax,%rax
je     1270 <main+0xa0>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x2c,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1367 <main+0x197>
mov    %r12,%rdi
lea    0xd01(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2c,-0x1(%rax,%r14,1)
jne    1270 <main+0xa0>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
jmp    1270 <main+0xa0>
cmpb   $0x2d,(%r12)
jne    1266 <main+0x96>
movzbl 0x1(%r12),%eax
test   %al,%al
je     1390 <main+0x1c0>
movsbl %al,%edi
call   1090 <isspace@plt>
mov    %r12,%r14
test   %rax,%rax
je     1270 <main+0xa0>
lea    0xc89(%rip),%r14
jmp    1270 <main+0xa0>

LLVM IR (-O0):
@.str = [6 x i8] c"lsmod\00"
@.str.1 = [14 x i8] c"/proc/modules\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Opening /proc/modules\00"
@.str.4 = [39 x i8] c"Module Size Used by\0A\00"
@.str.5 = [3 x i8] c" \09\00"
@.str.6 = [6 x i8] c"%-19s\00"
@.str.7 = [4 x i8] c" \09\0A\00"
@.str.8 = [5 x i8] c" %8s\00"
@.str.9 = [5 x i8] c" %s\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [1 x i8] zeroinitializer
@.str.12 = [3 x i8] c"\09 \00"
@.str.13 = [4 x i8] c" %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @print_usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %93, %20
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%24 = load i32*, i32** %7
%25 = call i64 @fgets(i8* %23, i32 4096, i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %95
27: ; preds = %22
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%29 = call i8* @strtok(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %33)
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %93
38: ; preds = %27
%39 = load i8*, i8** %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* %39)
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %38
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), i8** %8
br label %90
45: ; preds = %38
%46 = load i8*, i8** %8
%47 = call i64 @strchr(i8* %46, i8 signext 44)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %69
49: ; preds = %45
%50 = load i8*, i8** %8
%51 = call i8* @strtok(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = load i8*, i8** %8
%54 = call i32 @strlen(i8* %53)
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 44
br i1 %60, label %61, label %68
61: ; preds = %49
%62 = load i8*, i8** %8
%63 = load i8*, i8** %8
%64 = call i32 @strlen(i8* %63)
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %62, i64 %66
store i8 0, i8* %67
br label %68
68: ; preds = %61, %49
br label %89
69: ; preds = %45
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 45
br i1 %74, label %75, label %88
75: ; preds = %69
%76 = load i8*, i8** %8
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp eq i32 %79, 0
br i1 %80, label %87, label %81
81: ; preds = %75
%82 = load i8*, i8** %8
%83 = getelementptr inbounds i8, i8* %82, i64 1
%84 = load i8, i8* %83
%85 = call i64 @isspace(i8 signext %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %81, %75
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), i8** %8
br label %88
88: ; preds = %87, %81, %69
br label %89
89: ; preds = %88, %68
br label %90
90: ; preds = %89, %44
%91 = load i8*, i8** %8
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %90, %27
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %22
95: ; preds = %22
%96 = load i32*, i32** %7
%97 = call i32 @fclose(i32* %96)
%98 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"lsmod\00"
@.str.1 = [14 x i8] c"/proc/modules\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Opening /proc/modules\00"
@.str.5 = [3 x i8] c" \09\00"
@.str.6 = [6 x i8] c"%-19s\00"
@.str.7 = [4 x i8] c" \09\0A\00"
@.str.8 = [5 x i8] c" %8s\00"
@.str.9 = [5 x i8] c" %s\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [1 x i8] zeroinitializer
@.str.12 = [3 x i8] c"\09 \00"
@.str.13 = [4 x i8] c" %s\00"
@str = [38 x i8] c"Module Size Used by\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @print_usage(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%16 = call i64 @fgets(i8* %4, i32 4096, i32* %9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %63, label %18
18: ; preds = %14, %59
%19 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %21)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %59, label %25
25: ; preds = %18
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* %23)
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %56, label %29
29: ; preds = %25
%30 = call i64 @strchr(i8* %27, i8 signext 44)
%31 = icmp eq i64 %30, 0
br i1 %31, label %45, label %32
32: ; preds = %29
%33 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, -1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 44
br i1 %39, label %40, label %56
40: ; preds = %32
%41 = call i32 @strlen(i8* %33)
%42 = add nsw i32 %41, -1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %33, i64 %43
store i8 0, i8* %44
br label %56
45: ; preds = %29
%46 = load i8, i8* %27
%47 = icmp eq i8 %46, 45
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = getelementptr inbounds i8, i8* %27, i64 1
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = call i64 @isspace(i8 signext %50)
%54 = icmp eq i64 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %52, %48
br label %56
56: ; preds = %25, %40, %32, %55, %52, %45
%57 = phi i8* [ %33, %40 ], [ %33, %32 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), %55 ], [ %27, %52 ], [ %27, %45 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), %25 ]
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %18
%60 = call i32 @putchar(i32 10)
%61 = call i64 @fgets(i8* %4, i32 4096, i32* %9)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %18
63: ; preds = %59, %14
%64 = call i32 @fclose(i32* %9)
%65 = call i32 @exit(i32 0)
unreachable
}