#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 rcfile {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, unsigned int);
int rc_getstringptr(struct rcfile *, char const *, int, char const *, char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int strlen(char *);
int rc_getstring(struct rcfile *rcp, const char *section, int sect_id,
                 const char *key, unsigned int maxlen, char *dest) {
  char *value;
  int error;
  error = rc_getstringptr(rcp, section, sect_id, key, &value);
  if (error)
    return (error);
  if (strlen(value) >= maxlen) {
    fprintf(stderr,
            "line too long for key '%s' in section '%s',"
            "max = %d\n",
            key, section, maxlen);
    return (EINVAL);
  }
  strcpy(dest, value);
  return (0);
}


x86 assembly (clang, -O0):
<rc_getstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1060 <rc_getstringptr@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     118f <rc_getstring+0x4f>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <rc_getstring+0xa7>
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x2c(%rbp),%eax
jb     11d3 <rc_getstring+0x93>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <rc_getstring+0xa7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_getstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %rsi,%rbp
mov    %rsp,%r8
call   1060 <rc_getstringptr@plt>
test   %eax,%eax
jne    11a4 <rc_getstring+0x64>
mov    (%rsp),%rdi
call   1040 <strlen@plt>
cmp    %r14d,%eax
jae    117d <rc_getstring+0x3d>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    11a4 <rc_getstring+0x64>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r14d,%r8d
call   1050 <fprintf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rcfile = type { i32 }
@stderr = global i32 0
@.str = [53 x i8] c"line too long for key '%s' in section '%s',max = %d\0A\00"
@EINVAL = global i32 0
define i32 @rc_getstring(%struct.rcfile* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca %struct.rcfile*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store %struct.rcfile* %0, %struct.rcfile** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%16 = load %struct.rcfile*, %struct.rcfile** %8
%17 = load i8*, i8** %9
%18 = load i32, i32* %10
%19 = load i8*, i8** %11
%20 = call i32 @rc_getstringptr(%struct.rcfile* %16, i8* %17, i32 %18, i8* %19, i8** %14)
store i32 %20, i32* %15
%21 = load i32, i32* %15
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = load i32, i32* %15
store i32 %24, i32* %7
br label %41
25: ; preds = %6
%26 = load i8*, i8** %14
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* %12
%29 = icmp uge i32 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %11
%33 = load i8*, i8** %9
%34 = load i32, i32* %12
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %33, i32 %34)
%36 = load i32, i32* @EINVAL
store i32 %36, i32* %7
br label %41
37: ; preds = %25
%38 = load i8*, i8** %13
%39 = load i8*, i8** %14
%40 = call i32 @strcpy(i8* %38, i8* %39)
store i32 0, i32* %7
br label %41
41: ; preds = %37, %30, %23
%42 = load i32, i32* %7
ret i32 %42
}

LLVM IR (-O2):
%struct.rcfile = type { i32 }
@stderr = global i32 0
@.str = [53 x i8] c"line too long for key '%s' in section '%s',max = %d\0A\00"
@EINVAL = global i32 0
define i32 @rc_getstring(%struct.rcfile* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = bitcast i8** %7 to i8*
%9 = call i32 @rc_getstringptr(%struct.rcfile* %0, i8* %1, i32 %2, i8* %3, i8** %7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
%14 = icmp ult i32 %13, %4
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %1, i32 %4)
%18 = load i32, i32* @EINVAL
br label %22
19: ; preds = %11
%20 = load i8*, i8** %7
%21 = call i32 @strcpy(i8* %5, i8* %20)
br label %22
22: ; preds = %6, %19, %15
%23 = phi i32 [ %18, %15 ], [ 0, %19 ], [ %9, %6 ]
ret i32 %23
}