#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 /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int smb_readpamconf(char *smb_server, char *smb_server_addr, char *smb_backup,
                    char *smb_backup_addr, 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';
  char server_details[80];
  char *tok;
  fgets(server_details, 80, fl);
  tok = strtok(server_details, " ");
  if (!tok)
    return 1;
  strncpy(smb_server, tok, 50);
  tok = strtok(NULL, " ");
  if (tok) {
    strncpy(smb_server_addr, tok, 50);
  } else {
    smb_server_addr[0] = '\0';
  }
  fgets(server_details, 80, fl);
  tok = strtok(server_details, " ");
  if (!tok)
    return 1;
  strncpy(smb_backup, tok, 50);
  tok = strtok(NULL, " ");
  if (tok) {
    strncpy(smb_backup_addr, tok, 50);
  } else {
    smb_backup_addr[0] = '\0';
  }
  fclose(fl);
  return (0);
}


x86 assembly (clang, -O0):
<smb_readpamconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11ac <smb_readpamconf+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    1333 <smb_readpamconf+0x1d3>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x90(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    -0x90(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1224 <smb_readpamconf+0xc4>
movl   $0x1,-0x4(%rbp)
jmp    1333 <smb_readpamconf+0x1d3>
mov    -0x10(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd7(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     1278 <smb_readpamconf+0x118>
mov    -0x18(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
jmp    127f <smb_readpamconf+0x11f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    -0x90(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    12c8 <smb_readpamconf+0x168>
movl   $0x1,-0x4(%rbp)
jmp    1333 <smb_readpamconf+0x1d3>
mov    -0x20(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd33(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     131c <smb_readpamconf+0x1bc>
mov    -0x28(%rbp),%rdi
mov    -0x98(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
jmp    1323 <smb_readpamconf+0x1c3>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smb_readpamconf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,%rbp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe7c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1220 <smb_readpamconf+0xc0>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x32,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
lea    0xe46(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strtok@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1296 <smb_readpamconf+0x136>
mov    %r13,%rdi
mov    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
lea    0xe19(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1227 <smb_readpamconf+0xc7>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
jmp    122c <smb_readpamconf+0xcc>
mov    $0x1,%ebp
jmp    1296 <smb_readpamconf+0x136>
movb   $0x0,(%r12)
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
lea    0xdd5(%rip),%rsi
mov    %r12,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1296 <smb_readpamconf+0x136>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
lea    0xdb1(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1288 <smb_readpamconf+0x128>
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
jmp    128c <smb_readpamconf+0x12c>
movb   $0x0,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/etc/config/pam_smb.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
define i32 @smb_readpamconf(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca [80 x i8]
%15 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = 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* %16, i32** %12
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %5
store i32 1, i32* %6
br label %78
19: ; preds = %5
%20 = load i8*, i8** %11
%21 = load i32*, i32** %12
%22 = call i32 @fgets(i8* %20, i32 50, i32* %21)
%23 = load i8*, i8** %11
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %13
%25 = load i8*, i8** %11
%26 = load i32, i32* %13
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%31 = load i32*, i32** %12
%32 = call i32 @fgets(i8* %30, i32 80, i32* %31)
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%34 = call i8* @strtok(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %34, i8** %15
%35 = load i8*, i8** %15
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %19
store i32 1, i32* %6
br label %78
38: ; preds = %19
%39 = load i8*, i8** %7
%40 = load i8*, i8** %15
%41 = call i32 @strncpy(i8* %39, i8* %40, i32 50)
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %42, i8** %15
%43 = load i8*, i8** %15
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load i8*, i8** %8
%47 = load i8*, i8** %15
%48 = call i32 @strncpy(i8* %46, i8* %47, i32 50)
br label %52
49: ; preds = %38
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 0
store i8 0, i8* %51
br label %52
52: ; preds = %49, %45
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%54 = load i32*, i32** %12
%55 = call i32 @fgets(i8* %53, i32 80, i32* %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%57 = call i8* @strtok(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %57, i8** %15
%58 = load i8*, i8** %15
%59 = icmp ne i8* %58, null
br i1 %59, label %61, label %60
60: ; preds = %52
store i32 1, i32* %6
br label %78
61: ; preds = %52
%62 = load i8*, i8** %9
%63 = load i8*, i8** %15
%64 = call i32 @strncpy(i8* %62, i8* %63, i32 50)
%65 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %65, i8** %15
%66 = load i8*, i8** %15
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %72
68: ; preds = %61
%69 = load i8*, i8** %10
%70 = load i8*, i8** %15
%71 = call i32 @strncpy(i8* %69, i8* %70, i32 50)
br label %75
72: ; preds = %61
%73 = load i8*, i8** %10
%74 = getelementptr inbounds i8, i8* %73, i64 0
store i8 0, i8* %74
br label %75
75: ; preds = %72, %68
%76 = load i32*, i32** %12
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %6
br label %78
78: ; preds = %75, %60, %37, %18
%79 = load i32, i32* %6
ret i32 %79
}

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