#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 timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_D(char *, int, ...);
int atoi(char *);
int sendandrecv(char *, char *, struct timeval *, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
scalar_t__ strlen(char *);
int set_duration(char *pipe, char *value) {
  char *curindx = NULL;
  char *preindx = NULL;
  char data[32] = {0};
  int duration = 0;
  int rsp = 0;
  int ret, result;
  struct timeval timeout = {5, 0};
  if (strlen(value) != 0) {
    duration = atoi(value);
    if (0 < duration && duration <= 60) {
      sprintf(data, "%s=%d", "setduration", duration);
      ret = sendandrecv(pipe, data, &timeout, &rsp, sizeof(int));
      LOG_D("set duration %d sucess. ", rsp);
    } else {
      LOG_D("Because of ARM precious resource.the required duration %d bigger "
            "than the MAX duration %d must be fail.",
            duration, 60);
    }
  }
exit:
  return ret;
}


x86 assembly (clang, -O0):
<set_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    0xe5b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1246 <set_duration+0xe6>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x44(%rbp)
xor    %eax,%eax
cmp    -0x44(%rbp),%eax
jge    122b <set_duration+0xcb>
cmpl   $0x3c,-0x44(%rbp)
jg     122b <set_duration+0xcb>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%ecx
lea    0xe1d(%rip),%rsi
lea    0xe1c(%rip),%rdx
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x48(%rbp),%rcx
mov    $0x4,%r8d
call   1060 <sendandrecv@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <LOG_D@plt>
jmp    1241 <set_duration+0xe1>
mov    -0x44(%rbp),%esi
lea    0xdfe(%rip),%rdi
mov    $0x3c,%edx
mov    $0x0,%al
call   1040 <LOG_D@plt>
jmp    1246 <set_duration+0xe6>
jmp    124b <set_duration+0xeb>
mov    -0x4c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_duration>:
push   %r14
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x4(%rsp)
movq   $0x5,0x8(%rsp)
cmpb   $0x0,(%rsi)
je     11e2 <set_duration+0xa2>
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0x3b,%ecx
ja     11cd <set_duration+0x8d>
lea    0xe7a(%rip),%rsi
lea    0xe79(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%ecx
call   1060 <sprintf@plt>
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%r8d
call   1040 <sendandrecv@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1030 <LOG_D@plt>
jmp    11e2 <set_duration+0xa2>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
mov    $0x3c,%edx
xor    %eax,%eax
call   1030 <LOG_D@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@__const.set_duration.timeout = %struct.timeval { i32 5, i32 0 }
@.str = [6 x i8] c"%s=%d\00"
@.str.1 = [12 x i8] c"setduration\00"
@.str.2 = [25 x i8] c"set duration %d sucess. \00"
@.str.3 = [104 x i8] c"Because of ARM precious resource.the required duration %d bigger than the MAX duration %d must be fail.\00"
define i32 @set_duration(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [32 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
%13 = bitcast [32 x i8]* %7 to i8*
store i32 0, i32* %8
store i32 0, i32* %9
%14 = bitcast %struct.timeval* %12 to i8*
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %39
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 0, %21
br i1 %22, label %23, label %35
23: ; preds = %18
%24 = load i32, i32* %8
%25 = icmp sle i32 %24, 60
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* %8
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%32 = call i32 @sendandrecv(i8* %30, i8* %31, %struct.timeval* %12, i32* %9, i32 4)
store i32 %32, i32* %10
%33 = load i32, i32* %9
%34 = call i32 (i8*, i32, ...) @LOG_D(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %38
35: ; preds = %23, %18
%36 = load i32, i32* %8
%37 = call i32 (i8*, i32, ...) @LOG_D(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 60)
br label %38
38: ; preds = %35, %26
br label %39
39: ; preds = %38, %2
br label %40
40: ; preds = %39
%41 = load i32, i32* %10
ret i32 %41
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%s=%d\00"
@.str.1 = [12 x i8] c"setduration\00"
@.str.2 = [25 x i8] c"set duration %d sucess. \00"
@.str.3 = [104 x i8] c"Because of ARM precious resource.the required duration %d bigger than the MAX duration %d must be fail.\00"
define i32 @set_duration(i8* %0, i8* nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.timeval*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i64* %5 to i8*
store i64 5, i64* %5
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %2
%13 = tail call i32 @atoi(i8* %1)
%14 = add i32 %13, -1
%15 = icmp ult i32 %14, 60
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%18 = call i32 @sendandrecv(i8* %0, i8* %7, %struct.timeval* %6, i32* %4, i32 4)
%19 = load i32, i32* %4
%20 = call i32 (i8*, i32, ...) @LOG_D(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %23
21: ; preds = %12
%22 = tail call i32 (i8*, i32, ...) @LOG_D(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 60)
br label %23
23: ; preds = %2, %21, %16
%24 = phi i32 [ %18, %16 ], [ undef, %21 ], [ undef, %2 ]
ret i32 %24
}