#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 */
struct floppy_struct {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int scan_fdprm(int /*<<< orphan*/ *, char *, struct floppy_struct *,
               int /*<<< orphan*/);
int set_params(char **, struct floppy_struct *);
int parse_fdprm(int argc, char **argv, struct floppy_struct *ft) {
  FILE *f;
  int r;
  switch (argc) {
  case 1:
    if ((f = fopen("/etc/fdprm", "r")) == NULL)
      return 1;
    r = scan_fdprm(f, argv[0], ft, 0);
    fclose(f);
    return r;
  case 9:
    return set_params(argv, ft);
  default:
    return 1;
  }
}


x86 assembly (clang, -O0):
<parse_fdprm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1178 <parse_fdprm+0x38>
jmp    1167 <parse_fdprm+0x27>
mov    -0x28(%rbp),%eax
sub    $0x9,%eax
je     11d2 <parse_fdprm+0x92>
jmp    11e7 <parse_fdprm+0xa7>
lea    0xe81(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a5 <parse_fdprm+0x65>
movl   $0x1,-0x4(%rbp)
jmp    11ee <parse_fdprm+0xae>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <scan_fdprm@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <parse_fdprm+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <set_params@plt>
mov    %eax,-0x4(%rbp)
jmp    11ee <parse_fdprm+0xae>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_fdprm>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
cmp    $0x9,%edi
je     1199 <parse_fdprm+0x59>
cmp    $0x1,%edi
jne    118e <parse_fdprm+0x4e>
lea    0xea4(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118e <parse_fdprm+0x4e>
mov    %rax,%r15
mov    (%rbx),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <scan_fdprm@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    1193 <parse_fdprm+0x53>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <set_params@plt>

LLVM IR (-O0):
%struct.floppy_struct = type { i32 }
@.str = [11 x i8] c"/etc/fdprm\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @parse_fdprm(i32 %0, i8** %1, %struct.floppy_struct* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca %struct.floppy_struct*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store %struct.floppy_struct* %2, %struct.floppy_struct** %7
%10 = load i32, i32* %5
switch i32 %10, label %29 [
i32 1, label %11
i32 9, label %25
]
11: ; preds = %3
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %4
br label %30
15: ; preds = %11
%16 = load i32*, i32** %8
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load %struct.floppy_struct*, %struct.floppy_struct** %7
%21 = call i32 @scan_fdprm(i32* %16, i8* %19, %struct.floppy_struct* %20, i32 0)
store i32 %21, i32* %9
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %9
store i32 %24, i32* %4
br label %30
25: ; preds = %3
%26 = load i8**, i8*** %6
%27 = load %struct.floppy_struct*, %struct.floppy_struct** %7
%28 = call i32 @set_params(i8** %26, %struct.floppy_struct* %27)
store i32 %28, i32* %4
br label %30
29: ; preds = %3
store i32 1, i32* %4
br label %30
30: ; preds = %29, %25, %15, %14
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.floppy_struct = type { i32 }
@.str = [11 x i8] c"/etc/fdprm\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @parse_fdprm(i32 %0, i8** %1, %struct.floppy_struct* %2) {
switch i32 %0, label %13 [
i32 1, label %4
i32 9, label %11
]
4: ; preds = %3
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = load i8*, i8** %1
%9 = tail call i32 @scan_fdprm(i32* %5, i8* %8, %struct.floppy_struct* %2, i32 0)
%10 = tail call i32 @fclose(i32* %5)
br label %13
11: ; preds = %3
%12 = tail call i32 @set_params(i8** %1, %struct.floppy_struct* %2)
br label %13
13: ; preds = %3, %4, %11, %7
%14 = phi i32 [ %12, %11 ], [ %9, %7 ], [ 1, %4 ], [ 1, %3 ]
ret i32 %14
}