#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
int smb_readpamconf(char *smb_server, char *smb_backup, char *smb_domain) {
  FILE *fl;
  int len;
  if (!(fl = fopen("/etc/config/pam_smb.conf", "r"))) {
    return 1;
  }
  fgets(smb_domain, 50, fl);
  len = strlen(smb_domain);
  smb_domain[len - 1] = '\0';
  fgets(smb_server, 50, fl);
  len = strlen(smb_server);
  smb_server[len - 1] = '\0';
  fgets(smb_backup, 50, fl);
  len = strlen(smb_backup);
  smb_backup[len - 1] = '\0';
  fclose(fl);
  return (0);
}


x86 assembly (clang, -O0):
<smb_readpamconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xea5(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1181 <smb_readpamconf+0x41>
movl   $0x1,-0x4(%rbp)
jmp    121e <smb_readpamconf+0xde>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smb_readpamconf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea8(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d8 <smb_readpamconf+0x98>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x32,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r15,%rdi
mov    $0x32,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r14,%rdi
mov    $0x32,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11dd <smb_readpamconf+0x9d>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/etc/config/pam_smb.conf\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @smb_readpamconf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 1, i32* %4
br label %46
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = load i32*, i32** %8
%16 = call i32 @fgets(i8* %14, i32 50, i32* %15)
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %9
%19 = load i8*, i8** %7
%20 = load i32, i32* %9
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = load i32*, i32** %8
%26 = call i32 @fgets(i8* %24, i32 50, i32* %25)
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %9
%29 = load i8*, i8** %5
%30 = load i32, i32* %9
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = load i32*, i32** %8
%36 = call i32 @fgets(i8* %34, i32 50, i32* %35)
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
store i32 %38, i32* %9
%39 = load i8*, i8** %6
%40 = load i32, i32* %9
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %4
br label %46
46: ; preds = %13, %12
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [25 x i8] c"/etc/config/pam_smb.conf\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @smb_readpamconf(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = tail call i32 @fgets(i8* %2, i32 50, i32* %4)
%8 = tail call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @fgets(i8* %0, i32 50, i32* %4)
%13 = tail call i32 @strlen(i8* %0)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
%17 = tail call i32 @fgets(i8* %1, i32 50, i32* %4)
%18 = tail call i32 @strlen(i8* %1)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @fclose(i32* %4)
br label %23
23: ; preds = %3, %6
%24 = phi i32 [ 0, %6 ], [ 1, %3 ]
ret i32 %24
}