#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 EIO;
int createQueryURL(char const *, int, char const *, char *, int, char const **,
                   char const **, char **);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int snprintf(char *, int, char *, int);
int createUrlForCHMOD(const char *host, int nnPort, const char *path, int mode,
                      const char *user, char **url) {
  int strlength;
  char permission[4];
  const char *paraNames[2], *paraValues[2];
  paraNames[0] = "permission";
  paraNames[1] = "user.name";
  memset(permission, 0, 4);
  strlength = snprintf(permission, 4, "%o", mode);
  if (strlength < 0 || strlength >= 4) {
    return EIO;
  }
  paraValues[0] = permission;
  paraValues[1] = user;
  return createQueryURL(host, nnPort, path, "SETPERMISSION", 2, paraNames,
                        paraValues, url);
}


x86 assembly (clang, -O0):
<createUrlForCHMOD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0x4,%esi
lea    0xe8e(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     11a3 <createUrlForCHMOD+0x73>
cmpl   $0x4,-0x3c(%rbp)
jl     11b4 <createUrlForCHMOD+0x84>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <createUrlForCHMOD+0xc9>
lea    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x50(%rbp),%r9
lea    -0x60(%rbp),%r10
mov    -0x38(%rbp),%rax
lea    0xe36(%rip),%rcx
mov    $0x2,%r8d
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <createQueryURL@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createUrlForCHMOD>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,(%rsp)
mov    %r8,%rbp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r13
lea    0xea8(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xea7(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0xe91(%rip),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14d,%ecx
call   1030 <snprintf@plt>
cmp    $0x4,%eax
jb     11a4 <createUrlForCHMOD+0x74>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
jmp    11db <createUrlForCHMOD+0xab>
mov    %rbx,0x10(%rsp)
mov    %rbp,0x18(%rsp)
lea    0x10(%rsp),%rax
lea    0xe5e(%rip),%rcx
lea    0x20(%rsp),%r9
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    $0x2,%r8d
push   (%rsp)
push   %rax
call   1040 <createQueryURL@plt>
add    $0x10,%rsp
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"permission\00"
@.str.1 = [10 x i8] c"user.name\00"
@.str.2 = [3 x i8] c"%o\00"
@EIO = global i32 0
@.str.3 = [14 x i8] c"SETPERMISSION\00"
define i32 @createUrlForCHMOD(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i8** %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8**
%14 = alloca i32
%15 = alloca [4 x i8]
%16 = alloca [2 x i8*]
%17 = alloca [2 x i8*]
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8** %5, i8*** %13
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %16, i64 0, i64 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %16, i64 0, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 4)
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%23 = load i32, i32* %11
%24 = call i32 @snprintf(i8* %22, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %6
%28 = load i32, i32* %14
%29 = icmp sge i32 %28, 4
br i1 %29, label %30, label %32
30: ; preds = %27, %6
%31 = load i32, i32* @EIO
store i32 %31, i32* %7
br label %44
32: ; preds = %27
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %15, i64 0, i64 0
%34 = getelementptr inbounds [2 x i8*], [2 x i8*]* %17, i64 0, i64 0
store i8* %33, i8** %34
%35 = load i8*, i8** %12
%36 = getelementptr inbounds [2 x i8*], [2 x i8*]* %17, i64 0, i64 1
store i8* %35, i8** %36
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = load i8*, i8** %10
%40 = getelementptr inbounds [2 x i8*], [2 x i8*]* %16, i64 0, i64 0
%41 = getelementptr inbounds [2 x i8*], [2 x i8*]* %17, i64 0, i64 0
%42 = load i8**, i8*** %13
%43 = call i32 @createQueryURL(i8* %37, i32 %38, i8* %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 2, i8** %40, i8** %41, i8** %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %32, %30
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@.str = [11 x i8] c"permission\00"
@.str.1 = [10 x i8] c"user.name\00"
@.str.2 = [3 x i8] c"%o\00"
@EIO = global i32 0
@.str.3 = [14 x i8] c"SETPERMISSION\00"
define i32 @createUrlForCHMOD(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i8** %5) {
%7 = alloca [4 x i8]
%8 = alloca [2 x i8*]
%9 = alloca [2 x i8*]
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%11 = bitcast [2 x i8*]* %8 to i8*
%12 = bitcast [2 x i8*]* %9 to i8*
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %14
%15 = call i32 @memset(i8* %10, i32 0, i32 4)
%16 = call i32 @snprintf(i8* %10, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%17 = icmp ugt i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %6
%19 = load i32, i32* @EIO
br label %24
20: ; preds = %6
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
store i8* %10, i8** %21
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 1
store i8* %4, i8** %22
%23 = call i32 @createQueryURL(i8* %0, i32 %1, i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 2, i8** %13, i8** %21, i8** %5)
br label %24
24: ; preds = %20, %18
%25 = phi i32 [ %19, %18 ], [ %23, %20 ]
ret i32 %25
}