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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int lsmtab(void) {
  FILE *f;
  char tmp[160];
  char *dev;
  char *mntpt;
  char *fstype;
  char *rwflag;
  f = fopen("/etc/mtab", "r");
  if (f) {
    while (fgets(tmp, sizeof(tmp), f)) {
      dev = strtok(tmp, " ");
      mntpt = strtok(NULL, " ");
      fstype = strtok(NULL, " ");
      rwflag = strtok(NULL, "\n");
      if (strcmp(fstype, "swap") == 0)
        printf("%s is swapspace\n", dev);
      else
        printf("%s mounted on %s read-%s\n", dev, mntpt,
               (strcmp(rwflag, "ro") == 0) ? "only" : "write");
    }
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<lsmtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12b9 <lsmtab+0x159>
jmp    1192 <lsmtab+0x32>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0xa0,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12b0 <lsmtab+0x150>
lea    -0xb0(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0xb8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe36(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0xc0(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1f(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0xc8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1e(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1247 <lsmtab+0xe7>
mov    -0xb8(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ab <lsmtab+0x14b>
mov    -0xb8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xc0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd0(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1060 <strcmp@plt>
mov    -0xe0(%rbp),%rsi
mov    -0xd8(%rbp),%rdx
mov    %rax,%rdi
lea    0xdb8(%rip),%rcx
lea    0xdac(%rip),%rax
cmp    $0x0,%rdi
cmove  %rax,%rcx
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1192 <lsmtab+0x32>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lsmtab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     128e <lsmtab+0x12e>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0xa0,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1286 <lsmtab+0x126>
lea    0x10(%rsp),%rbp
mov    %rbx,0x8(%rsp)
jmp    1215 <lsmtab+0xb5>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
lea    0xe74(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe6d(%rip),%rcx
lea    0xe61(%rip),%rax
cmove  %rax,%rcx
lea    0xe39(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rbp
mov    0x8(%rsp),%rbx
mov    %rbp,%rdi
mov    $0xa0,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1286 <lsmtab+0x126>
mov    %rbp,%rbx
mov    %rbp,%rdi
lea    0xdea(%rip),%rbp
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
lea    0xdd2(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%r13
mov    %r15,%rdi
lea    0xdac(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11c0 <lsmtab+0x60>
lea    0xd9c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f8 <lsmtab+0x98>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"swap\00"
@.str.5 = [17 x i8] c"%s is swapspace\0A\00"
@.str.6 = [26 x i8] c"%s mounted on %s read-%s\0A\00"
@.str.7 = [3 x i8] c"ro\00"
@.str.8 = [5 x i8] c"only\00"
@.str.9 = [6 x i8] c"write\00"
define i32 @lsmtab() {
%1 = alloca i32*
%2 = alloca [160 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %1
%8 = load i32*, i32** %1
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %41
10: ; preds = %0
br label %11
11: ; preds = %37, %10
%12 = getelementptr inbounds [160 x i8], [160 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i64 @fgets(i8* %12, i32 160, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %11
%17 = getelementptr inbounds [160 x i8], [160 x i8]* %2, i64 0, i64 0
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %3
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %19, i8** %4
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %5
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %21, i8** %6
%22 = load i8*, i8** %5
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %26)
br label %37
28: ; preds = %16
%29 = load i8*, i8** %3
%30 = load i8*, i8** %4
%31 = load i8*, i8** %6
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0)
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %29, i8* %30, i8* %35)
br label %37
37: ; preds = %28, %25
br label %11
38: ; preds = %11
%39 = load i32*, i32** %1
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/etc/mtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"swap\00"
@.str.5 = [17 x i8] c"%s is swapspace\0A\00"
@.str.6 = [26 x i8] c"%s mounted on %s read-%s\0A\00"
@.str.7 = [3 x i8] c"ro\00"
@.str.8 = [5 x i8] c"only\00"
@.str.9 = [6 x i8] c"write\00"
define i32 @lsmtab() {
%1 = alloca [160 x i8]
%2 = getelementptr inbounds [160 x i8], [160 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %27, label %5
5: ; preds = %0
%6 = call i64 @fgets(i8* %2, i32 160, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %5, %22
%9 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %9)
br label %22
17: ; preds = %8
%18 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0)
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %9, i8* %10, i8* %20)
br label %22
22: ; preds = %17, %15
%23 = call i64 @fgets(i8* %2, i32 160, i32* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %8
25: ; preds = %22, %5
%26 = call i32 @fclose(i32* %3)
br label %27
27: ; preds = %25, %0
ret i32 0
}