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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int udisk_devlist_get_mounted(char *mtabfile,
                              char dev_list_mounted[][255 + 1]) {
  FILE *mtab;
  int i;
  if ((mtab = fopen(mtabfile, "r")) == NULL) {
    fprintf(stderr, "open %s failed\n", mtabfile);
    exit(1);
  }
  i = 0;
  while (fscanf(mtab, "%s", dev_list_mounted[i]) != EOF) {
    while (getc(mtab) != '\n')
      ;
    fprintf(stdout, "dev_list_mounted: %s\n", dev_list_mounted[i]);
    if (strncmp(dev_list_mounted[i], "/dev/sd", 7) == 0) {
      i++;
    }
  }
  strncpy(dev_list_mounted[i], "", 1);
  return 0;
}


x86 assembly (clang, -O0):
<udisk_devlist_get_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c1 <udisk_devlist_get_mounted+0x51>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rdx
lea    0xe30(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
je     1272 <udisk_devlist_get_mounted+0x102>
jmp    11fc <udisk_devlist_get_mounted+0x8c>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1216 <udisk_devlist_get_mounted+0xa6>
jmp    11fc <udisk_devlist_get_mounted+0x8c>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rdx
lea    0xde0(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rdi
lea    0xddb(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    126d <udisk_devlist_get_mounted+0xfd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c8 <udisk_devlist_get_mounted+0x58>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rdi
lea    0xd89(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udisk_devlist_get_mounted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1255 <udisk_devlist_get_mounted+0xe5>
mov    %rax,%rbx
lea    0xe72(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <fscanf@plt>
mov    0x2e36(%rip),%rcx
mov    %r14,%rbp
cmp    (%rcx),%rax
je     1230 <udisk_devlist_get_mounted+0xc0>
xor    %r15d,%r15d
lea    0xe67(%rip),%r12
lea    0xe47(%rip),%r13
mov    %r14,%rbp
xchg   %ax,%ax
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    $0xa,%al
jne    11d0 <udisk_devlist_get_mounted+0x60>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r15d
mov    %r15,%rbp
shl    $0x8,%rbp
add    %r14,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%rax
jne    11d0 <udisk_devlist_get_mounted+0x60>
lea    0xdda(%rip),%rsi
mov    %rbp,%rdi
mov    $0x1,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"open %s failed\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@stdout = global i32 0
@.str.3 = [22 x i8] c"dev_list_mounted: %s\0A\00"
@.str.4 = [8 x i8] c"/dev/sd\00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @udisk_devlist_get_mounted(i8* %0, [256 x i8]* %1) {
%3 = alloca i8*
%4 = alloca [256 x i8]*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store [256 x i8]* %1, [256 x i8]** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %51, %15
%17 = load i32*, i32** %5
%18 = load [256 x i8]*, [256 x i8]** %4
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 %20
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%23 = call i64 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i64, i64* @EOF
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %52
26: ; preds = %16
br label %27
27: ; preds = %32, %26
%28 = load i32*, i32** %5
%29 = call signext i8 @getc(i32* %28)
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %33
32: ; preds = %27
br label %27
33: ; preds = %27
%34 = load i32, i32* @stdout
%35 = load [256 x i8]*, [256 x i8]** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %35, i64 %37
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %38, i64 0, i64 0
%40 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load [256 x i8]*, [256 x i8]** %4
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %41, i64 %43
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %44, i64 0, i64 0
%46 = call i64 @strncmp(i8* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %33
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %51
51: ; preds = %48, %33
br label %16
52: ; preds = %16
%53 = load [256 x i8]*, [256 x i8]** %4
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %53, i64 %55
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %56, i64 0, i64 0
%58 = call i32 @strncpy(i8* %57, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"open %s failed\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@stdout = global i32 0
@.str.3 = [22 x i8] c"dev_list_mounted: %s\0A\00"
@.str.4 = [8 x i8] c"/dev/sd\00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @udisk_devlist_get_mounted(i8* %0, [256 x i8]* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = tail call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %32, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5, %20
%15 = phi i8* [ %28, %20 ], [ %6, %5 ]
%16 = phi i32 [ %26, %20 ], [ 0, %5 ]
br label %17
17: ; preds = %14, %17
%18 = tail call signext i8 @getc(i32* %3)
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %17
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%23 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %16, %25
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 %27, i64 0
%29 = tail call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %14
32: ; preds = %20, %5
%33 = phi i8* [ %6, %5 ], [ %28, %20 ]
%34 = tail call i32 @strncpy(i8* %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
ret i32 0
}