#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 */
typedef int /*<<< orphan*/ urle_user_name;
typedef int /*<<< orphan*/ urle_login_token;

/* Variables and functions */
scalar_t__ rc_url_encode(char *, int, char const *);
int snprintf(char *, size_t, char *, char *, char *, unsigned int);
int rc_url_get_patch(char *buffer, size_t size, const char *user_name,
                     const char *login_token, unsigned gameid) {
  char urle_user_name[64];
  char urle_login_token[64];
  int written;
  if (rc_url_encode(urle_user_name, sizeof(urle_user_name), user_name) != 0) {
    return -1;
  }
  if (rc_url_encode(urle_login_token, sizeof(urle_login_token), login_token) !=
      0) {
    return -1;
  }
  written = snprintf(
      buffer, size,
      "http://retroachievements.org/dorequest.php?r=patch&u=%s&t=%s&g=%u",
      urle_user_name, urle_login_token, gameid);
  return (size_t)written >= size ? -1 : 0;
}


x86 assembly (clang, -O0):
<rc_url_get_patch>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     1167 <rc_url_get_patch+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <rc_url_get_patch+0xb6>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     1192 <rc_url_get_patch+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <rc_url_get_patch+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x70(%rbp),%rcx
lea    -0xb0(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xe50(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0xb4(%rbp)
movslq -0xb4(%rbp),%rdx
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovae %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_url_get_patch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %r8d,%r14d
mov    %rcx,%rbp
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x40(%rsp),%rdi
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1190 <rc_url_get_patch+0x70>
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbp,%rdx
call   1030 <rc_url_encode@plt>
test   %rax,%rax
jne    1190 <rc_url_get_patch+0x70>
lea    0xe90(%rip),%rdx
lea    0x40(%rsp),%rcx
mov    %rsp,%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%r9d
call   1040 <snprintf@plt>
cltq
xor    %ebx,%ebx
cmp    %r15,%rax
adc    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"http://retroachievements.org/dorequest.php?r=patch&u=%s&t=%s&g=%u\00"
define i32 @rc_url_get_patch(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca [64 x i8]
%14 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%16 = load i8*, i8** %9
%17 = call i64 @rc_url_encode(i8* %15, i32 64, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %5
store i32 -1, i32* %6
br label %39
20: ; preds = %5
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%22 = load i8*, i8** %10
%23 = call i64 @rc_url_encode(i8* %21, i32 64, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %6
br label %39
26: ; preds = %20
%27 = load i8*, i8** %7
%28 = load i64, i64* %8
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%31 = load i32, i32* %11
%32 = call i32 @snprintf(i8* %27, i64 %28, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30, i32 %31)
store i32 %32, i32* %14
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = load i64, i64* %8
%36 = icmp uge i64 %34, %35
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 -1, i32 0
store i32 %38, i32* %6
br label %39
39: ; preds = %26, %25, %19
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
@.str = [66 x i8] c"http://retroachievements.org/dorequest.php?r=patch&u=%s&t=%s&g=%u\00"
define i32 @rc_url_get_patch(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%10 = call i64 @rc_url_encode(i8* %8, i32 64, i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %5
%13 = call i64 @rc_url_encode(i8* %9, i32 64, i8* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9, i32 %4)
%17 = sext i32 %16 to i64
%18 = icmp uge i64 %17, %1
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %12, %5, %15
%21 = phi i32 [ %19, %15 ], [ -1, %5 ], [ -1, %12 ]
ret i32 %21
}