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

/* Variables and functions */
int item_write(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int config_write(void) {
  char key[1024] = {0};
  char value[1024] = {0};
  int ret = 0;
  printf("input key:");
  scanf("%s", key);
  printf("input value:");
  scanf("%s", value);
  ret = item_write("./config.txt", key, value, strlen(value));
  if (ret != 0) {
    printf("func write configure file err:%d\n", ret);
    return ret;
  }
  printf("your write item is:%s = %s\n", key, value);
  return ret;
}


x86 assembly (clang, -O0):
<config_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x814(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x810(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x828(%rbp),%rsi
mov    -0x820(%rbp),%rdx
mov    %eax,%ecx
lea    0xe0f(%rip),%rdi
call   1030 <item_write@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
je     1246 <config_write+0xf6>
mov    -0x814(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126b <config_write+0x11b>
lea    -0x410(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_write>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
lea    0x400(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rsp,%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe71(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <item_write@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11f2 <config_write+0xa2>
lea    0xe41(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120b <config_write+0xbb>
lea    0xe51(%rip),%rdi
lea    0x400(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"input key:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [13 x i8] c"input value:\00"
@.str.3 = [13 x i8] c"./config.txt\00"
@.str.4 = [34 x i8] c"func write configure file err:%d\0A\00"
@.str.5 = [28 x i8] c"your write item is:%s = %s\0A\00"
define i32 @config_write() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = bitcast [1024 x i8]* %2 to i8*
%6 = bitcast [1024 x i8]* %3 to i8*
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @item_write(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %14, i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %0
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %4
store i32 %23, i32* %1
br label %29
24: ; preds = %0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %25, i8* %26)
%28 = load i32, i32* %4
store i32 %28, i32* %1
br label %29
29: ; preds = %24, %20
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"input key:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [13 x i8] c"input value:\00"
@.str.3 = [13 x i8] c"./config.txt\00"
@.str.4 = [34 x i8] c"func write configure file err:%d\0A\00"
@.str.5 = [28 x i8] c"your write item is:%s = %s\0A\00"
define i32 @config_write() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @item_write(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %4, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %10)
br label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %3, i8* %4)
br label %16
16: ; preds = %14, %12
ret i32 %10
}