#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
scalar_t__ fileCalculateOffset(int);
int /*<<< orphan*/ lseek(int, scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int fileUpdateValue(int shardID, int KVID, char *value) {
  int fd, i;
  char fileName[5];
  char cleanValue[20];
  sprintf(fileName, "f%d", shardID);
  fd = open(fileName, O_RDWR, S_IRUSR | S_IWUSR);
  if (fd < 0)
    return -1;
  for (i = 0; i < 20; i++)
    cleanValue[i] = '\0';
  sprintf(cleanValue, "%s", value);
  lseek(fd, fileCalculateOffset(KVID) + 20, SEEK_SET);
  write(fd, cleanValue, 20);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<fileUpdateValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x25(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x25(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    0x2e3c(%rip),%rax
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c4 <fileUpdateValue+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    1248 <fileUpdateValue+0xe8>
movl   $0x0,-0x20(%rbp)
cmpl   $0x14,-0x20(%rbp)
jge    11ec <fileUpdateValue+0x8c>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cb <fileUpdateValue+0x6b>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <fileCalculateOffset@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rsi
add    $0x14,%rsi
mov    0x2daf(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileUpdateValue>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%edx
lea    0xe75(%rip),%rsi
xor    %ebx,%ebx
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e1c(%rip),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1219 <fileUpdateValue+0xa9>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14d,%edi
call   1090 <fileCalculateOffset@plt>
lea    0x14(%rax),%rsi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <lseek@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x14,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    121e <fileUpdateValue+0xae>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"f%d\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@SEEK_SET = global i32 0
define i32 @fileUpdateValue(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [5 x i8]
%11 = alloca [20 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%13 = load i32, i32* %5
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %15, i32 %16, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 -1, i32* %4
br label %50
24: ; preds = %3
store i32 0, i32* %9
br label %25
25: ; preds = %32, %24
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %28
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %25
35: ; preds = %25
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%37 = load i8*, i8** %7
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = call i64 @fileCalculateOffset(i32 %40)
%42 = add nsw i64 %41, 20
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @lseek(i32 %39, i64 %42, i32 %43)
%45 = load i32, i32* %8
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%47 = call i32 @write(i32 %45, i8* %46, i32 20)
%48 = load i32, i32* %8
%49 = call i32 @close(i32 %48)
store i32 0, i32* %4
br label %50
50: ; preds = %35, %23
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"f%d\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_SET = global i32 0
define i32 @fileUpdateValue(i32 %0, i32 %1, i8* nocapture %2) {
%4 = alloca [5 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = call i32 @open(i8* %6, i32 %9, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %3
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%17 = call i8* @strcpy(i8* %7, i8* dereferenceable(1) %2)
%18 = call i64 @fileCalculateOffset(i32 %1)
%19 = add nsw i64 %18, 20
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %13, i64 %19, i32 %20)
%22 = call i32 @write(i32 %13, i8* %7, i32 20)
%23 = call i32 @close(i32 %13)
br label %24
24: ; preds = %3, %15
%25 = phi i32 [ 0, %15 ], [ -1, %3 ]
ret i32 %25
}